方法不允许(#405)
Method not allowed(#405)
以下代码会抛出这样的错误:
“不允许的方法 (#405)
方法不允许。本url只能处理以下请求方式:.
任何想法,如何解决这个问题?
['label' => 'Logout', 'url' => ['/site/logout'], 'linkOptions' => ['data' => ['method' => 'post']]],
这里仍然是 SiteController 中的方法:
public function actionLogout() {
Yii::$app->user->logout();
return $this->goHome();
}
在链接选项中使用数据方法
['label' => 'logOut',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
],
注意:检查站点控制器中的行为
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'dashboard'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
以下代码会抛出这样的错误: “不允许的方法 (#405) 方法不允许。本url只能处理以下请求方式:.
任何想法,如何解决这个问题?
['label' => 'Logout', 'url' => ['/site/logout'], 'linkOptions' => ['data' => ['method' => 'post']]],
这里仍然是 SiteController 中的方法:
public function actionLogout() {
Yii::$app->user->logout();
return $this->goHome();
}
在链接选项中使用数据方法
['label' => 'logOut',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
],
注意:检查站点控制器中的行为
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'dashboard'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}