Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii2 change controller action in gridview

I have ItemController and in actionView I put gridview of my Itempicture, and I want when I click on icon view, update and delete then go to ItempictureController.

so How to change controller action in gridview with different controller?

like image 583
Dedy Kurniawan Avatar asked May 08 '14 02:05

Dedy Kurniawan


2 Answers

You need to set $controller property of yii\grid\ActionColumn. In your case, try this:

[
    'class' => 'yii\grid\ActionColumn',
    'controller' => 'itempicture'
]

http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html#$controller-detail

If you are using yii\data\ArrayDataProvider, make sure you set $key property like:

$dataProvider->key = 'id'; //id is the primary key name of your Itempicture model.

http://www.yiiframework.com/doc-2.0/yii-data-arraydataprovider.html#$key-detail

Hope it helps.

like image 81
Clint Liang Avatar answered Sep 30 '22 13:09

Clint Liang


In your gridview,add like

[
  'class' => 'yii\grid\ActionColumn',
  'template' => '{new_action1}{new_action2}',
  'buttons' => [
    'new_action1' => function ($url, $model) {
        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', 'controller/action?id='.$model->id, [
                    'title' => Yii::t('app', 'New Action1'),
        ]);
    }
  ],
],

Hope this will work!

like image 38
Dency G B Avatar answered Sep 30 '22 12:09

Dency G B