Hey Nate,

Thanks for your time! What I'm trying to do evolves around virtual
fields. For instance in the user model, the afterFind() method creates
2 virtual fields, one named name_lf and containing a user full name in
'lastname, firstname' format. This works like a charm.

Now if I edit a user, and save my changes, if the beforeSave() in the
User Model returns false, nothing is saved to the db, and the 'error
mode' is triggered, the edit form shown again. (that's a pretty
standard cake behaviour)

Now that's from where my question was raised; because the user data is
stored in the post, it's not pulled from the DB again - which is great.
However because it's not pulled again, the afterFind() in the User
Model is not called, and the name_lf virtual field not created. Because
of that and because I'm using this virtual field in the edit form, I
get an error about this name_lf not being defined, hence my question,
when should a beforeSave return false..?!

Code?
function afterFind($results) {
   if (is_array($results)) {
       foreach ($results as $key => $obj) {
           if (!isset($obj[$this->name]['id'])) {
               continue;
           }
           $results[$key][$this->name]['name_lf'] =
($obj[$this->name]['lname'] ? $obj[$this->name]['lname'] . ', ' : '') .
$obj[$this->name]['fname'];
       }
   }
   return parent::afterFind($results);
}

function beforeSave() {
   // say I was to do something here... db related or not... and
something fails... which is possible according to the manual
   return false;
}

==== end code====


So.. yeah... I don't think I'm doing anything wrong... and am just
wondering why this all could be...

Cheers!

Seb.


On Jan 6, 5:09 am, "nate" <[EMAIL PROTECTED]> wrote:
Ummm.....  beforeSave() and afterFind() are normally completely
unrelated.  It might help to post a code sample so we can see what it
is that you're trying to do.


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

Reply via email to