Ahh, thank you very much Mr Tufty. Another piece of the Cake puzzle
slides into place :-)

On Nov 29, 4:28 pm, MrTufty <[EMAIL PROTECTED]> wrote:
> And is entirely wrong... well, no, it'll work, but it doesn't take
> advantage of CakePHP 1.2 validation. The IBM tutorials are good, but
> outdated now.
>
> Richard, as you suspect, you're not supposed to be referencing
> isUnique in a rule. But, you don't need to use it in the controller.
> Here's how you're supposed to do it:
>
> 1. Create a new function "checkUnique" inside the model you want to
> validate - or even in AppModel, if you're planning on using the
> functionality across multiple models. (you can actually call the
> function whatever you like)
> 2. In your validation rule, change "isUnique" to "checkUnique", or
> whatever you called the function.
> 3. The checkUnique function should basically call the isUnique
> function.
>
> It takes a bit of figuring out, but stick with the 1.2 validation
> method rather than the old fallback methods. It's well worth it in
> terms of code clarity and ease of use.
>
> Here's an example of how I use it to ensure an email address can only
> be registered once:
>
>         function checkUnique($data) {
>             return $this->isUnique(array('email' => $this->data['User']
> ['email']));
>         }
>
> It shouldn't take much to make that generic, I just went for the
> simplest solution.
>
> On Nov 29, 3:58 pm, sMAshdot <[EMAIL PROTECTED]> wrote:
>
> > On 29 Nov., 13:40, RichardAtHome <[EMAIL PROTECTED]> wrote:
>
> > > As a side note, I suspect isUnique might not meant to be referenced in
> > > a rule and is meant to be referenced in the controller. If this is
> > > true can someone point me towards some examples of how / where it
> > > should be used?
>
> > I'm quite new to CakePHP as well, but I check for uniqueness after
> > validating
> > the data.
>
> > This example comes from the IBM CakePHP 
> > tutorialshttp://www.ibm.com/developerworks/views/opensource/libraryview.jsp?se...
>
> > if ( $this->User->validates($this->data) )
> > {
> >   if ( $this->User->findByname($this->data['User']['name']) )
> >   {
> >     $this->User->invalidate('name');
> >     $this->set('name_error', 'User already exists.');
> >   }
>
> > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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