Вопрос

I have $model1, $model2 and OwnerID populated in my controller and it renders the data in my zii.widgets.grid.CGridView Problem comes in when I want to send $model2 to the view as well like so:

$this->render('listView', array('model1'=>$model, 'model2' => $model2, 'OwnerID' => 14));

and in the view I have:

$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)'
        ),
    ),
));

I get "Undefined variable: model2" There is data in $model2, if I comment out the dropDown in the grid and have the dropdown list outside the grid like so:

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

then everything works fine. How can I add the dropDownList in CGridView? $model1 is a list of file and $model2 is a list of users.

Это было полезно?

Решение

$model2 needs to be a string or a variable recognized by CGridView.

To get a string representation of the array use var_export()

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

To make $model2 a CGridView variable you'd need to extend CGridView as explained in this Yii wiki page

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top