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

Do you get this error Method Not Allowed. This url can only handle the following request methods: POST. with Yii Framework version 2? In this tutorial I will explain how you can solve this error.

Open your controller file and edit this function:

public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}

You must only replace 'logout' => ['post'], with 'logout' => ['get']. In this way your error will be solved.

This way works only with Yii Framework version 2.









Leave a Comment