我想从系统&我在下面写了代码:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['signin', 'logout', 'register', 'index'],
'rules' => [
[
'allow' => true,
'actions' => ['index', 'signin', 'register'],
'roles' => ['?'],
],
[
'allow' => true,
'actions' => ['logout'],
'roles' => ['@'],
],
],
// 'rules' => [
// [
// 'allow' => true,
// 'actions' => ['logout'],
// 'roles' => ['@'],
// ],
// [
// 'actions' => ['update', 'profile', 'delete', 'all', 'add'],
// 'allow' => true,
// 'verbs' => ['GET', 'POST'],
// 'roles' => ['@'],
// ],
// [
// 'actions' => ['signin', 'register'],
// 'allow' => true,
// 'roles' => ['?'], // guests
// 'verbs' => ['GET', 'POST'],
// ],
// [
// 'actions' => ['index'],
// 'allow' => true,
// 'verbs' => ['GET', 'POST'],
// 'roles' => ['?'],
// ],
// ],
'denyCallback' => function ($rule, $action) {
throw new \Exception('You are not allowed to access this page');
//// $this->redirect(['daxilol']);
},
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['POST', 'PUT'],
],
],
];
}
如您所见,我尝试了太多方法让用户退出。但在我的每次尝试中它都会返回:
异常
您无权访问此页面
我做错了什么?
答案 0 :(得分:1)
尝试避免顶部的唯一条款
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'actions' => ['index', 'signin', 'register'],
'roles' => ['?'],
],
[
'allow' => true,
'actions' => ['logout'],
'roles' => ['@'],
],
[
'allow' => false,
'actions' => ['register'],
'roles' => ['@'],
],
],
],