Why logout is not working in Yii2?

Good evening!

Understand that Voros jaded, I watched the search for the toaster: Yii2 not working data-method=post? - the answer is not found.

The bottom line:

There is a link to logout:

<?= Html::a("Exit", 'site/logout', [
 'data' =--> [
 'method' => 'post'
],
 ['class' => 'white text-center']
]
 );?>


Also in SiteController:

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


Well AppAsset.php:
class AppAsset extends AssetBundle
{
 public $basePath = '@webroot';
 public $baseUrl = '@web';
 public $css = [
'css/site.css',
'css/sticky-footer-navbar.css',
'css/main.css',
'css/fstyle.css',
];
 public $js = [
'js/main.js'
];
 public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}


Like all of science, but it does not work out.

The website on Yii2 basic.

Logout code:

public function actionLogout()
{
Yii::$app->user->logout();

 return $this->goHome();
 }


In the config:

'user' => [
 'identityClass' => 'app\models\User',
 'enableAutoLogin' => true,
 ],
July 9th 19 at 10:20
2 answers
July 9th 19 at 10:22
I guess you lomites in the get request to logout, but you are only allowed post requests yii2 must meet the 405 response status ( if I guessed correctly )

Remove or add
'verbs' => [
 'class' => VerbFilter::className(),
 'actions' => [
 'logout' => ['get','post'],
],
 ],
Unfortunately did not help(( - eudora.King87 commented on July 9th 19 at 10:25
July 9th 19 at 10:24
solved the problem.

<?= Html::a("Exit", ['site/logout'], [
 'data' =--> [
 'method' => 'post'
],
 ['class' => 'white text-center']
]
 );?>


added square brackets ['site/logout'] and it worked... how so?
and before that it was /logout ? - eudora.King87 commented on July 9th 19 at 10:27
just 'site/logout' - glennie_Rempel10 commented on July 9th 19 at 10:30

Find more questions by tags Yii