Can't you just do:
'name' => array(
'unique' => array(
'rule' => 'checkName',
'message' => 'Logtype name must be unique.'
)
)
Which will then call Logtype::checkName() directly. Seems easier than
faffing around with 'userDefined'...
On Sep 27, 12:14 am, Morten Nielsen <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I'm sure I'm overlooking something obvious here, but... well, I'm
> probably blind...
>
> I've been trying to fire a userDefined validation function (1.2:5695),
> to check whether a unique key already exists in the DB.
>
> In my $validate in the Logtype class I've got: (excerpt)
> 'name' => array(
> 'unique' => array(
> 'rule' => array('userDefined', 'Logtype', 'checkName'),
> 'message' => 'Logtype name must be unique.'
> )
> )
>
> and, I've got this function in my Logtype class also (the 'Temp'
> parameter in the find-call is just for test purposes)
>
> function checkName() {
> if ($this->findByName('Temp')) {
> return false; // error - a Logtype with this name already exists
> }
> else {
> return true;
> }
> }
>
> Problem is, only thing this throws back into my face is "*Fatal error*:
> Using $this when not in object context in
> */usr/home/mln/sarbe/models/logtype.php* on line *43*", line 43 being
> the if-statement of the function.
>
> Thus having demasked myself as somewhat of a newbie, I hope somebody is
> able to enlighten me :-)
>
> Yours
> Morten
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---