2016-10-04 5 views
1

あなたのデータ提出を確認することができません:yii2すると、削除のGridView:私はGridViewの上のアイテムを削除したい場合は、私はこのエラーを取得する

exception 'yii\web\BadRequestHttpException' with message 'Unable to verify your data submission. 

私のこの私のコントローラのコード:

class DevisController extends Controller 
{ 
public $layout = 'lay-admin'; 

public function behaviors() 
{ 
    return [ 
     'verbs' => [ 
      'class' => VerbFilter::className(), 
      'actions' => [ 
       'delete' => ['post'], 
      ], 
     ], 
    ]; 
} 
/* ..... */ 
public function actionDelete($id) 
{ 
    $this->findModel($id)->delete(); 

    return $this->redirect(['index']); 
} 

そして、私は、このエラーに

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

GridViewのコードを取得する行動関数のgetメソッドにPOSTメソッドを変更します。

<?= GridView::widget([ 
    'dataProvider' => $dataProvider, 
    'filterModel' => $searchModel, 
       'columns' => [ 
        ['class' => 'yii\grid\SerialColumn'], 

        //'idDevis', 
        'reference', 
        'client', 
        'dateCreation', 
        'contact', 
        'valableJusqua', 
        'dateRelance', 
        [ 
        'attribute'=>'etat', 
        'filter'=>ArrayHelper::map(Devis::find()->asArray()->all(), 'etat', 'etat'), 
        ], 
        'commercial', 
        'modePaiement', 
        'delaiPaiement', 

        ['class' => 'yii\grid\ActionColumn'], 
       ], 
]); ?> 

ご意見ください!

+0

ビューにCSRFパラメータがありますか? – Bizley

+0

私はこのパラメータを見ることができません。 –

+0

このメソッドは「メソッドが許可されていません。このURLは次のリクエストメソッドしか処理できません:POST.' –

答えて

2

カスタムレイアウトファイルにCSRFメタタグを追加します。

例:

<?php $this->beginPage() ?> 
<!DOCTYPE html> 
<html lang="<?= Yii::$app->language ?>"> 
<head> 
    <meta charset="<?= Yii::$app->charset ?>"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 

    <?= Html::csrfMetaTags() ?> 

    <title><?= Html::encode($this->title) ?></title> 
    <?php $this->head() ?> 
</head> 
<body> 
<?php $this->beginBody() ?> 

Here you can read more about CSRF

+0

それは動作します、ありがとうございます –

+0

強力な答えは、多くの場所を検索しました。 – Bira

関連する問題