php - Yii - reacting to attribute model assignation -
i want following in yii:
when attribute `a` in model class `m` set, something.
and tried using setter like: seta($value)
it's not called since yii cactiverecord
first detects if attribute exists in database (and assigns it) , if not exist in database (i.e. it's not table attribute) normal instance variable looked up. final fallback calling property accesor.
(edit - wrong resolution order: lookup seems first instance variable, attribute, , accessor - anyway, problem still same since accesor resolved if no database field exists name)
here it's shown internal mechanics of __set (and bit upper, __get).
question: how can invert order, @ least attribute? means: want capture database field edition setter seta($value)
, performing field assignation (i.e. actual $this->a, should done without falling in stack overflow error) inside seta
method
a reasonable approach override cactiverecord::setattribute
in model class behave way need to:
class m extends cactiverecord { .... public function setattribute($name,$value) { if($name === 'a') { .. } return parent::setattribute($name, $value); } .... }
Comments
Post a Comment