Ash McKenzie Sun Nov 07 17:48:57 -0500 2010

Subject: [SOLVED] Best approach to 'virtual attributes' ?

[UPDATE] Sorry all, I found the answer.. feel like a bit of a dope! - http://www.phpactiverecord.org/docs/ActiveRecord/Serialization#var$attributes

Hi.

Just wondering what's the best approach to achieving 'virtual attributes', similar to http://railscasts.com/episodes/16-virtual-attributes ?

I've been using __get() and __set(), but wondering if there's a nicer way ?

Thanks,

Ash.


Benjamin P Tue Nov 09 10:24:30 -0500 2010

See http://www.phpactiverecord.org/docs/ActiveRecord/Model#method__set :
You can define a method set_virtual_name($value) and get_virtual_name() - these will be called by $model->virtual_name.
(Note that for v1.0, you need to declare those setters&getters in the static variables $setters/$getters - nightly build will do it without them.)

(1-1/1)