Search code examples
phpyii2yii-extensionsyii2-advanced-app

Changing kartik dynagrid action column


Am using kartik yii2 dynagrid.Am trying to change the action delete actioncolumn but i get an error that

Method Not Allowed. This url can only handle the following request methods: POST.

My code :

['class' => 'kartik\grid\ActionColumn','dropdown'=>false,
    'order'=>DynaGrid::ORDER_FIX_RIGHT,
                      'template'=>'{delete}',
                        'buttons'=>[
                          'delete' => function ($url, $model) {     
           return Html::a('<span class="glyphicon glyphicon-plus"></span>', $url, [
                                    'title' => Yii::t('yii', 'delete'),
                            ]);                                

                          }
                      ]                            
]

The other actions work well but changing the 'template'=>'delete' but only delete action fails.


Solution

  • Include data-method= "post" attribute to your anchor tag

            'delete' => function ($url, $model) {
                      return Html::a('<span class="glyphicon glyphicon-plus"></span>', $url,
    
                          [  
                             'title' => Yii::t('yii', 'delete'),
                             'data-confirm' => "Are you sure you want to delete this item?",
                             'data-method' => 'post',
                             'data-pjax' => 0
                          ]);
                 }