CallBack
class CallBack (View source)
Callbacks allow the programmer to hook into the life cycle of a {@link 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
Properties
static protected array | $VALID_CALLBACKS | List of available callbacks. |
Methods
Creates a CallBack.
Returns all the callbacks registered for a callback type.
Invokes a callback.
Register a new callback.
Details
at line 140
array
get_callbacks($name)
Returns all the callbacks registered for a callback type.
at line 159
mixed
invoke(string $model, string $name, boolean $must_exist = true)
Invokes a callback.
at line 211
void
register(string $name, mixed $closure_or_method_name = null, array $options = array())
Register a new callback.
The option array can contain the following parameters:
- prepend: Add this callback at the beginning of the existing callbacks (true) or at the end (false, default)