php - yii2 会话超时后将任何页面重定向到登录页面
问题描述
我想问一下yii2会话超时后将任何页面重定向到登录页面,我尝试这样做
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => false,
'returnUrl' => 'index.php?r=site/login',
'identityCookie' => [
'name' => '_backendIdentity',
],
],
'session' => [
'name' => 'BACKENDSESSID',
'savePath' => __DIR__ . '/../runtime',
],
但是当我在 index.php 页面时它会返回登录页面,如果我去另一个动作并且会话超时它将返回
PHP 通知 – yii\base\ErrorException Trying to get property of non-object
1. in /var/www/html/spmoa/backend/controllers/StaffController.php at line 174
165166167168169170171172173174175176177178179180181182183
public function actionMyProfile() {
error here -> $id = Yii::$app->user->identity->staff->id;
$model = $this->findModel($id);
请帮我
解决方案
尝试行为
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['youraction'],
'allow' => true,
'roles' => ['@'], // you can use matchCallback to create more powerful check
],
],
],
];`enter code here`
}
推荐阅读
- python - 在 Dataframe 中查找共同值
- laravel - OR 和 AND 运算符在 laravel 中不起作用
- reactjs - 响应式导航栏切换按钮不起作用
- marklogic - corb2 与 MarkLogic 的兼容性检查
- python - 如何检查存储为 url 的图像的文件类型?
- r-markdown - 使用 Rmarkdown 在 Beamer 演示文稿中插入导航栏
- python - 错误的正则表达式或奇怪的行为?
- python - AttributeError:“PathCollection”对象没有属性“hue”
- python - 从matlab到python的尺寸错误
- python - unittest - 使 setUp() 成为测试数据的唯一真实来源及其对并行测试的影响