I am beginner for Yii2. By default, the framework provides View|Update|Delete buttons in the list view. The following code displays above action buttons.
[
'class' => 'yii\grid\ActionColumn',
...
...
],
Now I want to add one more button (i.e. Book Now) in this ActionColumn. I also tried with 'button' but I get error. May be I didn't use properly.
So I will be thankful to you for your help.
This is an example how you can to 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}'
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With