【问题标题】:How to check is there any session in Yii2 without write check session it in each page?如何检查 Yii2 中是否有任何会话而不在每个页面中写入检查会话?
【发布时间】:2018-09-23 22:59:20
【问题描述】:

我有一个使用 Yii2 框架的应用程序,使用应用程序的步骤:

  1. 访问localhost/college/web/login
  2. 使用用户名和密码登录
  3. 选择月份(在这里用户选择月份,然后选择的月份将被设置到session中)并点击提交

然后应用程序将显示所选月份的数据,在控制器中,我使用所选月份的会话来过滤数据。

在这里,我有一个问题,如果用户通过 url localhost/college/web/student/index 等访问应用程序(除了 localhost/college/web/login em>),应用会重定向到登录页面,输入登录凭据后,应用会将用户重定向到页面localhost/college/web/student/index,然后页面会显示错误页。因为没有选定月份的会话。

如何设置如果没有会话然后重定向到登录页面而不在每个页面中写入if(!isset(session'selected-month'){ render 'login'; })

【问题讨论】:

  • 你如何设置这个月的会话?
  • 你能展示你的代码吗?

标签: php session yii2


【解决方案1】:

我认为它可以帮助您Yii RBAC根据您的需要创建自己的基本控制器和越冬行为功能。

[
    'class' => AccessControl::className(),
    ...
    'denyCallback' => function ($rule, $action) {
        throw new \Exception('You are not allowed to access this page');
    }
]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 2010-11-23
    相关资源
    最近更新 更多