Yii Framework Forum: model assigns attribute to other model - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

model assigns attribute to other model one model attribute should get assigned to other module Rate Topic: -----

#1 User is offline   ps_sach 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 07-December 09

Posted 10 March 2010 - 05:15 AM

Hi there,

I want to assign one model attribute to other model dynamically. How I can do that ?

example :

$model1 -> $model2 -> Attribute = "String";

Thanks in advance
0

#2 User is offline   Onman 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 175
  • Joined: 26-December 09
  • Location:The Netherlands

Posted 10 March 2010 - 05:34 AM

You could use something like:
$model1->attr = $model2->otherAttr = "String";

To achieve this you should override the setOtherAttr method of $model2 and let it return the value it just set.
Or, for a more generic approach, you could override the __set method something like this:

class Model2 extends CFormModel    // or extend CActiveRecord
{
...
public function __set($prop, $value)
{
[indent]
parent::__set($prop, $value);
return $value;
[/indent]
}
...
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users