【发布时间】:2016-06-29 04:28:11
【问题描述】:
删除所有表中的记录时出错:
An Error occurred while handling another error:
exception 'yii\web\ForbiddenHttpException' with message 'You are not allowed to perform this action.' in D:\FORBIDDEN\projects\UniServerZ\www\project\vendor\yiisoft\yii2\filters\AccessControl.php:151
Stack trace:
Previous exception:
exception 'yii\web\MethodNotAllowedHttpException' with message 'Method Not Allowed. This url can only handle the following request methods: POST.' in D:\FORBIDDEN\projects\UniServerZ\www\project\vendor\yiisoft\yii2\filters\VerbFilter.php:105
Stack trace:
_
这是我的控制器:
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
和 view.php 中的删除按钮
<?= Html::a('Delete', ['delete', 'id' => $model->id_transaksi], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
])
?>
当我用 GET 替换 POST 时它工作,但警告确认不工作..
你知道怎么了?请帮忙
【问题讨论】:
-
在
GET的情况下删除method,因为url已经发出了GET请求 -
你能验证你的 Yii 资产是否被正确地包含进来了吗?我的意思是请确认它是否真的触发了 POST 请求