2013-03-27 60 views
0

我有$ model1,$ model2和OwnerID填充在我的控制器中,它呈现在我的zii.widgets.grid.CGridView中的数据当我想发送$ model2到视图时出现问题还有像这样:在Yii cGrid中的下拉列表 - 2个变量

$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数据,如果我注释掉下拉网格并在网格外部有下拉列表,如下所示:

<?php echo CHtml::dropDownList("partyList","owner_party_id", $model2) ?> 

然后一切正常。我如何在CGridView中添加d​​ropDownList? $ model1是文件列表,$ model2是用户列表。

回答

0

$model2需要是一个字符串或由CGridView识别的变量。

为了获取数组的字符串表示使用var_export()

... 
'value'=>'CHtml::dropDownList("partyList","owner_party_id",'.var_export($model2).')', 
... 

为了$model2一个CGridView变量你需要延长CGridView作为解释in this Yii wiki page

+0

甜,感谢“托弗”我不能让var_export工作(也试过implode?),但扩展CGridView的链接非常简单并且工作。 – 2013-03-28 16:23:11