class Model_Property extends \Orm\Model
{
protected static $_properties = array(
'name',
'custom' => array(
'data_type' => 'serialize',
),
);
protected static $_observers = array(
'Orm\\Observer_Self',
'Orm\\Observer_Typing'
);
public function _event_before_insert()
{
$this->custom = \Config::get('defaults.property.custom', array());
}
}
$property = Model_Property::forge(array('name' => 'Name'))
$property->save();
// launch `before_save` observers:
// Observer_Self::_event_before_save();
// $property->custom is still empty here
// Observer_Typing::_event_before_save();
// launch `before_insert` observers:
// Observer_Self::_event_before_insert();
// $property->custom = array()
// Catching Database_Exception here because `custom` property is unserialized yet.
public function _event_before_save()
{
if ($this->is_new())
{
$this->custom = \Config::get('defaults.property.custom', array());
}
}
class Observer_Typing
{
public static $events = array(
'before_save' => 'before',
'after_save' => 'after',
'after_load' => 'after',
);
}
It looks like you're new here. If you want to get involved, click one of these buttons!