You need to set the number before you validate the data... so you
could add that loop to the beforeValidate callback to set the proper
number. The downside to that is validating a model will actually
change it's state too, which might no be expected.

On Tue, Aug 10, 2010 at 9:18 AM, Tomfox Wiranata
<[email protected]> wrote:
> hi,
>
> i need to check if a specific, randomly generated number already
> exists in the database. when it does exist, a new number needs to be
> created and checked too. until there is a number, that doesn't exist
> already..
>
> the check in my model for existance:
>
> function validatenumber($data)
> {
>  $test = $this->find(array('number' => $data), array('user_id'));
>
>  if(empty('test') == true)
>    return true;
>  return false;
> }
>
> now i can make a working check, but only once in my controller:
>
> $x=rand(10,100000);
>
> if($test=$this->Linkable->validatenumber($x) == true)
> {
>   return $x:
> }else{
>   ....
> }
>
>
> but how can i make a loop to create numbers as long as one is not
> already taken? is there sth like a for loop? havent seen anything like
> that yet
>
> thank you so much :)
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to