Answer the question
In order to leave comments, you need to log in
Why is logout not working in Yii2?
Good evening!
I understand that the voros is hackneyed, I looked at the search on the toaster: Yii2 does not work data-method=post? - did not find the answer.
Bottom line:
There is a logout link:
<?= Html::a("Выход", 'site/logout', [
'data' => [
'method' => 'post'
],
['class' => 'white text-center']
]
);?>
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
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',
];
}
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
Answer the question
In order to leave comments, you need to log in
I suppose you are breaking on get request to logout, and you only allow post requests there yii2 should respond with 405 response status (if I guessed correctly)
Remove or add
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['get','post'],
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question