How To Add Attribute To The Owner Model From Behaviour


(Manas Sahoo) #1

In my application i want to add additional attribute to the owner model through its behaviours

I have a model to which a behaviour is attached i want to add attributes to that model form the behaviour

How to add additional attributes to the model from the attach($owner) method of behaviour

This is my attach method

//how can i add the code for adding additional attribute to the model

public function attach($owner)

{

$owner->metaData->addRelation( 'gallery', array(CActiveRecord::HAS_ONE, 'Gallery', 'principal_id') );





}


parent::attach($owner);

}


(Raul1234587) #2

Please make it a bit more elaborate. :rolleyes:


(Developer) #3

I’m not sure if you can add ‘attributes’ (assume properties). Why not just declare the properties in the model you are declaring the behavior in? (This is what I do).


(Alirz23) #4

I should not be difficult since Yii is PHP. I would suggest you read the blog tutorial here is useful link might help you understand better

http://www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods/