Method not allowed(405) on logout ?

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]);

Did you set up correctly the verb filter for the controller?

yes… my verb filter code is




 'verbs' => [

                'class' => VerbFilter::className(),

                'actions' => [

                    'logout' => ['post'],

                ],

            ],

Also the access rule?

is like this?




[

  'actions' => ['logout'],

  'allow' => true,

  'roles' => ['@'],

],




'rules' => [

                    [

                        'allow' => true,

                        'roles' => ['?'],

                    ]

                ],

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 ?

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