yii2 change controller action in gridview

21,147

Solution 1

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!

Solution 2

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.

Solution 3

Try this:

[
   'class' => 'yii\grid\ActionColumn',
   'template'    => '{view}',
   'controller' => 'ItempictureController'
]

https://github.com/yiisoft/yii2/blob/master/docs/guide/output-data-widgets.md#action-column

Solution 4

[
   'class' => 'yii\grid\ActionColumn',
   'template'    => '{view}',
   'controller' => 'itempicture'
]
Share:
21,147
Dedy Kurniawan
Author by

Dedy Kurniawan

Updated on October 05, 2020

Comments

  • Dedy Kurniawan
    Dedy Kurniawan over 3 years

    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?