Я создал 2 таблицы (message, source_message) для CDbMessageSource. Для CGridView колонки я выполняю данный код:
array('name' => 'Russian', 'value' => function ($data){
foreach ($data->messages as $msg) ...
}),
Мне выдаёт данную ошибку:
PHP Error
Invalid argument supplied for foreach()
C:\...\yii\framework\db\ar\CActiveFinder.php(838)
826 {
827 // determine the primary key value
828 if(is_string($this->_pkAlias)) // single key
829 {
830 if(isset($row[$this->_pkAlias]))
831 $pk=$row[$this->_pkAlias];
832 else // no matching related objects
833 return null;
834 }
835 else // is_array, composite key
836 {
837 $pk=array();
838 foreach($this->_pkAlias as $name=>$alias) // <=<=<=<= ТУТ ПОКАЗЫВАЕТ ОШИБКУ
839 {
840 if(isset($row[$alias]))
841 $pk[$name]=$row[$alias];
842 else // no matching related objects
843 return null;
844 }
845 $pk=serialize($pk);
846 }
847
848 // retrieve or populate the record according to the primary key value
849 if(isset($this->records[$pk]))
850 $record=$this->records[$pk];
Ниже привожу код моделей:
public function tableName()
{
return 'source_message';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('category', 'length', 'max'=>32),
array('message', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, category, message', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
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(
'messages' => array(self::HAS_MANY, 'Message', 'id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => Yii::t('adm', 'ID'),
'category' => Yii::t('adm', 'Category'),
'message' => Yii::t('adm', 'Message'),
);
}
public function tableName()
{
return 'message';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id, language', 'required'),
array('id', 'numerical', 'integerOnly'=>true),
array('language', 'length', 'max'=>4),
array('translation', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, language, translation', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
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(
'language0' => array(self::BELONGS_TO, 'Language', 'language'),
'id0' => array(self::BELONGS_TO, 'SourceMessage', 'id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => Yii::t('adm', 'ID'),
'language' => Yii::t('adm', 'Language'),
'translation' => Yii::t('adm', 'Translation'),
);
}
В чём может быть проблема и как её можно решить?