MD.MD
MD.MD

Reputation: 718

Get model attributes values from CActiveDataProvider in Yii

I have zii.widgets.grid.CGridView and I applied to it a CActiveDataProvider from different model, for example:

In the users model I used zii.widgets.grid.CGridView to display the articles that the user created, so when the user clicks on view, update, delete buttons, he should go to the articles controller actions, not to the users controller.

Here is my code:

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'articles-grid',
    'dataProvider'=>$ar,
    'filter'=>$articles,
    'columns'=>array(
                'title',
                'category',
                'display',
                'priority',
                'newsBanner',
                'idUser',
                'date',
        array(
            'class'=>'CButtonColumn',
                     'viewButtonUrl' =>"Yii::app()->createUrl('articles\view', array('id'=>'idUser'))"
        ),
    ),
));

the idUser that used in the url should be the same value as the idUser that used in the columns array in the widget, so how I can do that?

Upvotes: 0

Views: 804

Answers (1)

Let me see
Let me see

Reputation: 5094

you need to change

'viewButtonUrl' =>"Yii::app()->createUrl('articles\view', array('id'=>'idUser'))"

to

'viewButtonUrl' =>'Yii::app()->createUrl("articles/view", array("id"=>"$data->idUser"))'

Note:-

I have changed idUser to $data->idUser

Upvotes: 1

Related Questions