Yii2 - add an additional button to the Action field

I'm starting for Yii2. By default, the list | View | buttons are provided in the list view. Update | Delete The following code is displayed above the action buttons.

[ 'class' => 'yii\grid\ActionColumn', ... ... ], 

Now I want to add another button (i.e. Book) in this ActionColumn. I also tried with the 'button', but I get an error. Perhaps I did not use it properly.

Therefore, I will be grateful for your help.

+6
source share
1 answer

This is an example of how you can add buttons:

 [ 'class' => 'yii\grid\ActionColumn', 'context' => $this->context, 'buttons' => [ 'edit' => function ($model, $key, $index, $instance) { $urlConfig = []; foreach ($model->primaryKey() as $pk) { $urlConfig[$pk] = $model->$pk; $urlConfig['type'] = $model->type; } $url = Url::toRoute(array_merge(['modify'], $urlConfig)); return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [ 'title' => \Yii::t('yii', 'Update'), 'data-pjax' => '0', ]); }, 'remove' => function ($model, $key, $index, $instance) { $urlConfig = []; foreach ($model->primaryKey() as $pk) { $urlConfig[$pk] = $model->$pk; $urlConfig['type'] = $model->type; } $url = Url::toRoute(array_merge(['delete'], $urlConfig)); return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [ 'title' => \Yii::t('yii', 'Delete'), 'data-confirm' => \Yii::t('yii', 'Are you sure to delete this item?'), 'data-method' => 'post', 'data-pjax' => '0', ]); } ], 'template' => '{edit}{remove}' ], 
+6
source

Source: https://habr.com/ru/post/984975/


All Articles