Yii2 注销管理部分无法正常工作
Yii2 Logout admin part doesnt work correct
我用的是Yii2进阶版。 Everyhting 运行良好,但只有在我的管理面板中注销才能正常工作。当我单击“注销”时,它使我进入 index.php 并且不让我退出,第二次单击 ot 退出它使我进入 login.php ,但是当我尝试连接到管理部分时,实际上我是仍然登录...如果我等待 15-20 sek 它会注销我并将我撕成 login.php...我真的不明白想要继续...
这是我的操作:
<li class="dropdown menu-merge">
<a href="#" class="dropdown-toggle fw600 p15" data-toggle="dropdown">
<span class="hidden-xs pl15"><?php echo Yii::t('app', 'Hi'); ?>, <?php echo Yii::$app->user->identity->username; ?></span>
<span class="caret caret-tp hidden-xs"></span>
</a>
<ul class="dropdown-menu list-group dropdown-persist w250" role="menu">
<li class="dropdown-footer">
<a href="/admin/user/settings/profile" class="">
<span class="glyphicons glyphicons-user"></span> <?php echo Yii::t('app', 'Profile'); ?> </a>
</li>
<li class="dropdown-footer">
<a>
<?php
echo Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'<span class="fa fa-power-off pr5"></span>' . Yii::t('app', 'Logout'), ['class' => 'btn-link']
)
. Html::endForm()
?>
</a>
</li>
</ul>
</li>
这是动作
public function actionLogout() {
Yii::$app->user->logout();
return $this->goHome();
}
我的行为操作中的设置:
public function behaviors() {
if (Yii::$app->user->identity) {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'allow' => true,
'roles' => ['SuperAdmin', 'Admin'],
],
[
'actions' => ['selectaddress', 'addproductreview', 'clearallspecs', 'addincomparelist', 'makeexpressorder', 'buyproductwithqty', 'loadcolorgallery', 'drawgraph', 'addproductcomment',
'addfornewsletter', 'setspecval', 'addrating', 'deletefromwishlist', 'deletefromcomparelist', 'tbi', 'buyproduct', 'deleteproductfromcart', 'deleteallproducts',
'changeqtyfromcartup', 'changeqtyfromcartdown', 'addinwishlist'],
'allow' => true,
],
],
'denyCallback' => function ($rule, $action) {
return $this->redirect('/bg/user/logout');
},
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
} else {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'allow' => true,
'roles' => ['SuperAdmin', 'Admin'],
],
[
'actions' => ['selectaddress', 'addproductreview', 'clearallspecs', 'addincomparelist', 'makeexpressorder', 'buyproductwithqty', 'loadcolorgallery', 'drawgraph', 'addproductcomment',
'addfornewsletter', 'setspecval', 'addrating', 'deletefromwishlist', 'deletefromcomparelist', 'tbi', 'buyproduct', 'deleteproductfromcart', 'deleteallproducts',
'changeqtyfromcartup', 'changeqtyfromcartdown', 'addinwishlist'],
'allow' => true,
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
}
在 rules
中使用此数组
[
'allow' => true,
'action'=>['logout','index'],
'roles' => ['@'],
],
并将其用于注销
Html::a(
'Sign out', ['/site/logout'], ['data-method' => 'post', 'class' => 'btn btn-default btn-flat']
)
我用的是Yii2进阶版。 Everyhting 运行良好,但只有在我的管理面板中注销才能正常工作。当我单击“注销”时,它使我进入 index.php 并且不让我退出,第二次单击 ot 退出它使我进入 login.php ,但是当我尝试连接到管理部分时,实际上我是仍然登录...如果我等待 15-20 sek 它会注销我并将我撕成 login.php...我真的不明白想要继续... 这是我的操作:
<li class="dropdown menu-merge">
<a href="#" class="dropdown-toggle fw600 p15" data-toggle="dropdown">
<span class="hidden-xs pl15"><?php echo Yii::t('app', 'Hi'); ?>, <?php echo Yii::$app->user->identity->username; ?></span>
<span class="caret caret-tp hidden-xs"></span>
</a>
<ul class="dropdown-menu list-group dropdown-persist w250" role="menu">
<li class="dropdown-footer">
<a href="/admin/user/settings/profile" class="">
<span class="glyphicons glyphicons-user"></span> <?php echo Yii::t('app', 'Profile'); ?> </a>
</li>
<li class="dropdown-footer">
<a>
<?php
echo Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'<span class="fa fa-power-off pr5"></span>' . Yii::t('app', 'Logout'), ['class' => 'btn-link']
)
. Html::endForm()
?>
</a>
</li>
</ul>
</li>
这是动作
public function actionLogout() {
Yii::$app->user->logout();
return $this->goHome();
}
我的行为操作中的设置:
public function behaviors() {
if (Yii::$app->user->identity) {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'allow' => true,
'roles' => ['SuperAdmin', 'Admin'],
],
[
'actions' => ['selectaddress', 'addproductreview', 'clearallspecs', 'addincomparelist', 'makeexpressorder', 'buyproductwithqty', 'loadcolorgallery', 'drawgraph', 'addproductcomment',
'addfornewsletter', 'setspecval', 'addrating', 'deletefromwishlist', 'deletefromcomparelist', 'tbi', 'buyproduct', 'deleteproductfromcart', 'deleteallproducts',
'changeqtyfromcartup', 'changeqtyfromcartdown', 'addinwishlist'],
'allow' => true,
],
],
'denyCallback' => function ($rule, $action) {
return $this->redirect('/bg/user/logout');
},
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
} else {
return [
'access' => [
'class' => AccessControl::className(),
'ruleConfig' => [
'class' => AccessRule::className(),
],
'rules' => [
[
'allow' => true,
'roles' => ['SuperAdmin', 'Admin'],
],
[
'actions' => ['selectaddress', 'addproductreview', 'clearallspecs', 'addincomparelist', 'makeexpressorder', 'buyproductwithqty', 'loadcolorgallery', 'drawgraph', 'addproductcomment',
'addfornewsletter', 'setspecval', 'addrating', 'deletefromwishlist', 'deletefromcomparelist', 'tbi', 'buyproduct', 'deleteproductfromcart', 'deleteallproducts',
'changeqtyfromcartup', 'changeqtyfromcartdown', 'addinwishlist'],
'allow' => true,
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
}
在 rules
[
'allow' => true,
'action'=>['logout','index'],
'roles' => ['@'],
],
并将其用于注销
Html::a(
'Sign out', ['/site/logout'], ['data-method' => 'post', 'class' => 'btn btn-default btn-flat']
)