Class Details
Callbacks allow the programmer to hook into the life cycle of a Model.
You can control the state of your object by declaring certain methods to be called before or after methods are invoked on your object inside of ActiveRecord.
Valid callbacks are:
- after_construct: called after a model has been constructed
- before_save: called before a model is saved
- after_save: called after a model is saved
- before_create: called before a NEW model is to be inserted into the database
- after_create: called after a NEW model has been inserted into the database
- before_update: called before an existing model has been saved
- after_update: called after an existing model has been saved
- before_validation: called before running validators
- after_validation: called after running validators
- before_validation_on_create: called before validation on a NEW model being inserted
- after_validation_on_create: called after validation on a NEW model being inserted
- before_validation_on_update: see above except for an existing model being saved
- after_validation_on_update: ...
- before_destroy: called after a model has been deleted
- after_destroy: called after a model has been deleted
This class isn't meant to be used directly. Callbacks are defined on your model like the example below:
class Person extends ActiveRecord\Model { static $before_save = array('make_name_uppercase'); static $after_save = array('do_happy_dance'); public function make_name_uppercase() { $this->name = strtoupper($this->name); } public function do_happy_dance() { happy_dance(); } }
Available options for callbacks:
- prepend: puts the callback at the top of the callback chain instead of the bottom