// Entity model
[...]
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'metaFields' => array(self::HAS_MANY, 'MetaField', 'entity_id', 'order'=>'sort_order ASC'),
'modules' => array(self::MANY_MANY, 'EntityMod', '{{entity_to_entity_mod}}(entity_id, module_id)'),
'activeModules' => array(self::MANY_MANY, 'EntityMod', '{{entity_to_entity_mod}}(entity_id, module_id)', 'condition'=>'`status`=:st','params'=>array(':st'=>self::STATUS_ACTIVE)),
'htmlBlocks' => array(self::MANY_MANY, 'HtmlBlock', '{{html_block_to_entity}}(entity_id, block_id)'),
);
}
public function getMetaField($str)
{
static $loadedFields=array();
if(isset($loadedFields[$str]))
return $loadedFields[$str];
if(empty($this->metaFields))
return null;
foreach($this->metaFields AS $field)
{
if($field->key===$str||$field->field_id===$str||$field->label===$str)
{
$loadedFields[$str]=$field->value;
return $loadedFields[$str];
}
}
return null;
}
[...]
Calling:
<?php echo $model->getMetaField('meta-title');?>
Throws
Indirect modification of overloaded property Entity::$metaFields has no effect
The error is thrown when the execution reaches the foreach() loop, and i think it is happening because of the __get() magic method implementation from CActiveRecord.
Shouldn’t yii be php > 5.1.0 compatible and this error should never happen ?
This happens on Linux Debian, PHP 5.2.0, Apache 2.2.x, with Yii 1.1.10