2013-03-27 61 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