On Tue, Apr 21, 2009 at 5:31 PM, Dave Maharaj :: WidePixels.com
<[email protected]> wrote:
> I am trying to generate a 6 character unique id using this in my model:
>
> function generateJobKey()
>       {
>           // creates a 6 digit key
>           $key = substr(md5(uniqid(rand(), true)),0,6);
>     //checkto make sure its not a duplcate
>           $q = $this->find('first', array('conditions', array('Job.key' =>
> $key)));
>     if(!$q){
>      //if founds re-run the function
>      $this->generateJobKey();
>
>     } else {
>    return $key;
>     }
>  }

It should be:
if ($q){
     //if founds re-run the function
      return $this->generateJobKey();

You want to make a new query if $q is not empty. Then, you need to
return properly or the 2nd call will produce nothing.

--~--~---------~--~----~------------~-------~--~----~
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