I am getting a Bad Request (#405) Error on logout and a couple of other actions,which were working ok.can’t redirect to logout page
my button code for logout is
<a href="<?= Url::to(['site/logout'])?>" data-method="post">Logout</a>
My SiteController logout action is as follows:
$model = new LoginForm();
$this->layout = 'index';
return $this->render(' ', ['model' => $model]);
grischer
(Alberto)
2
Did you set up correctly the verb filter for the controller?
yes… my verb filter code is
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
grischer
(Alberto)
4
Also the access rule?
is like this?
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
'rules' => [
[
'allow' => true,
'roles' => ['?'],
]
],
grischer
(Alberto)
6
Try to modify your rule as i posted, so logout should work.
Anyway the correct way to setup rule is to follow this guide:
http://www.yiiframework.com/doc-2.0/yii-filters-accesscontrol.html
Or to use rbac system.
thanks Grischer…but i used a get method in login so when i changed rules into post an error comes in actionlogin…how can i fix it ?
grischer
(Alberto)
8
You should change also in login or setup your logout for get
If you need more help it could be helpful to see the code you are using