Thorsten Krug Tue Apr 23 15:22:16 -0400 2013

Subject: after_load method?

I'm quite new to active record, so please excuse if my question seems stupid.

One can hook into "before_save" like:

class Orders extends ActiveRecord\Model {
static $before_save = array('serialize_items');
public function serialize_items(){
$this->items = serialize ( $this->items );
}
}

Is there a corresponding function I can hook in on loading data from the database?
A "after_load" method?


Koen Punt Tue Apr 23 18:13:56 -0400 2013

You can define a custom getter http://www.phpactiverecord.org/projects/main/wiki/Utilities#attribute-getters

An example:

class Orders extends ActiveRecord\Model {
static $before_save = array('serialize_items');
public function serialize_items(){
$this->items = serialize ( $this->items );
}
public function get_items(){
return unserialize($this->read_attribute('items'));
}
}

(1-1/1)