以下代码抛出这样的错误: “不允许的方法(#405) 方法不允许。此网址只能处理以下请求方法:。“
任何想法,如何解决这个问题?
['label' => 'Logout', 'url' => ['/site/logout'], 'linkOptions' => ['data' => ['method' => 'post']]],
这是SiteController中的方法:
public function actionLogout() {
Yii::$app->user->logout();
return $this->goHome();
}
答案 0 :(得分:1)
在linkOptions中使用data-method
['label' => 'logOut',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
],
注意:检查sitecontroller中的行为
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'dashboard'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}