parent::beforeSave parent::afterFind

I’ve seen a couple of these in examples.

protected function beforeSave()




similar for parent:afterFind()

Should I be doing this for all functions that have been overridden? And should I put them before or after my code?

Thanks, Russ

the "before" methods need to return a boolean value and also check what the parent function returned.

If the parent function returned a boolean false, you don’t want the script to keep running(something went wrong, so we stop), that’s why you will do:

public function beforeSave()



      return false;


   //do things here.

   return true;


The “after” methods are easier, you don’t care about the parent function neither if the parent function returned true or false(actually the parent methods won’t return anything, in the best case, they will run some code, but mostly, they are just placeholders for your event handlers), so:

public function afterSave()


   //run code here


Note: those are not just methods(as in my example), they are actually event handlers for onBeforeSave/onAfterSave events.