Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 - To add Additional Button in Action Column [duplicate]

Tags:

button

yii2

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.

like image 278
npcoder Avatar asked Apr 11 '15 03:04

npcoder


1 Answers

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}'
],
like image 187
Fortran Avatar answered Nov 13 '22 21:11

Fortran