yii2 change controller action in gridview

a 夏天 提交于 2019-12-21 04:46:20

问题


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?


回答1:


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.




回答2:


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!




回答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




回答4:


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


来源:https://stackoverflow.com/questions/23531523/yii2-change-controller-action-in-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!