I'm having a hard time understanding how advanced validation is
intended to be used in Cake, and it actually seems to be somewhat of a
moving target.
The code below (condensed for readability) used to work before the most
recent release of CakePHP (don't have the version number handy), but
now it generates PHP errors:
-------------------------
In my controller:
-------------------------
if (!$this->fooBar('someData')) $this->User->invalidate('name');
if ($this->User->validates() &&
$this->User->save($this->params['data'])) {
[ Do some cool stuff ]
}
-----------------------------
In my model (User):
-----------------------------
function beforeValidate() {
$this->data['User']['name'] = trim($this->data['User']['name']);
return true;
}
When executng this, the index 'User' is not defined in
beforeValidate(), so PHP throws an error - which means that the model
does not get ->data passed correctly. Removing the
'$this->User->validates()' from the controller logic allows the script
to proceed without error, with ->data getting passed to the User model.
The identical code worked prior to the recent CakePHP update, and the
validates() function has indeed changed.
I know I must be missing something about how beforeValidate(),
validates() and the other validation constructs are supposed to be
used, but I just can't figure out what it is, and the posts, example
code, wiki, API docs, etc haven't been much help so far.
Any guidance would be appreciated.
Thanks,
Stephen
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---