nate wrote:
> Well first of all, you're calling validates() before you're calling
> save(), so the data that gets set in save() isn't there in the
> validate() call.
>
> Also, if you're doing any custom validation in your controller, you
> should use set() to set the data to the model, and call save() with no
> parameters.  Otherwise, save() will call set(), and when a previously
> invalidated field gets overwritten, the validation error goes away
> (which is only logical, since the data has changed).
>
> Additionally, the call to validates() is unnecessary, since save() will
> validate by default, and return false if validation fails.  Thus, your
> new code should look more like the following:
>
> $this->User->set($this->data);
>
> if (!$this->fooBar('someData')) {
>     $this->User->invalidate('name');
> }
>
> if ($this->User->save( )) {
>         [ Do some cool stuff ]
> }
>
> (The model code is fine as-is.)

First nate, thanks for your reply. My understanding is that
Model->save() fires the callbacks beforeValidate(), and beforeSave() in
that order, and that validates() fires beforeValidate() before checking
any conditions in the $validate property of the model, and that you
could use this information along with invalidate() for custom
validation logic.

In my attempt to simplify my example, I provided a nonsensical bit of
controller code, but the point I was trying to establish was that
calling validates() in my controller used to work (meaning my
controller could find out about the validation status of a model to
potentially perform other actions before trying to call save()), and
now it doesn't work.

What it sounds like you're saying is that before using validates() I
need to set() the Model, which doesn't make that much sense to me, so
some questions:

Shouldn't validates() already know how to set() the Model - otherwise
it's pretty useless on it's own, no?

Should i just override validates() if I want to use it this way?

Does this mean that save() is the only method that automatically sets
the Model before the callbacks are triggered?

Thanks again,

Stephen

As I read back through this I'm realizing that maybe validates() gets
called as part of save's work...::shrug::


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

Reply via email to