GSTAR
(Omzy83)
1
Suppose in my Listing model I have:
public $categories;
and in my ListingController I do:
$model->attributes = unserialize($other_model->categories);
Now when I do:
print_r($model->attributes);
it does not include ‘categories’.
Any reason why?
Keith
(Kburton)
2
Make sure you have a rule set for that attribute in your rules() method.
GSTAR
(Omzy83)
3
I have. Just to be extra sure I even set a ‘safe’ rule for the attribute.
Keith
(Kburton)
4
Should you not use this?
$model->categories = $other_model->categories;
I’m not quite sure of the relationship between your two models.
GSTAR
(Omzy83)
5
I use unserialize because I’m storing this data as a serialized array.
Either way I suppose the question is, does $model->attributes include virtual attributes?
Keith
(Kburton)
6
I believe so, as long as the attribute has rules defined for the current scenario.
tomvdp
(Tomvdp)
7
I do not think so ?
CModel:
public function setAttributes($values,$safeOnly=true){
if(!is_array($values))
return;
$attributes=array_flip($safeOnly ? $this->getSafeAttributeNames() : $this->attributeNames());
...
CActiveRecord:
public function attributeNames()
{
return array_keys($this->getMetaData()->columns);
}
Unless you are explicitly setting only safe attributes, the selected attributes are those from the database table.