我在我的控制器中填充了$ model1,$ model2和OwnerID,它在我的zii.widgets.grid.CGridView中呈现数据当我想将$ model2发送到视图时问题就出现了:
$this->render('listView', array('model1'=>$model, 'model2' => $model2, 'OwnerID' => 14));
在视图中我有:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'listKeys',
'dataProvider'=>$model1->search($OwnerID),
'summaryText'=>'Showing {start} to {end} of {count} keys.',
'columns'=>array(
array('value'=>'$data["id"]', 'header'=>'Key ID'),
array(
'type'=>'raw',
'header'=>'Edit',
'value'=>'CHtml::dropDownList("partyList","owner_party_id", $model2)'
),
),
));
我得到“未定义的变量:model2 ”$ model2中有数据,如果我在网格中注释掉dropDown并且在网格外面有下拉列表,如下所示:
<?php echo CHtml::dropDownList("partyList","owner_party_id", $model2) ?>
然后一切正常。如何在CGridView中添加dropDownList? $ model1是文件列表,$ model2是用户列表。
答案 0 :(得分:0)
$model2
必须是CGridView
识别的字符串或变量。
要获取数组的字符串表示形式,请使用var_export()
...
'value'=>'CHtml::dropDownList("partyList","owner_party_id",'.var_export($model2).')',
...
要使$model2
成为CGridView
变量,您需要按照in this Yii wiki page
CGridView