在预控制器codeigniter钩子中访问CI会话 [英] access the CI session in a pre controller codeigniter hook

查看:298
本文介绍了在预控制器codeigniter钩子中访问CI会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个预控制器钩子检测和设置网站语言从会话/ cookie /浏览器lang检测..这样的答案:
Codeigniter语言

I am using a pre controller hook to detect and set the site language from the session/cookie/browser lang detection.. something like this answer: Codeigniter language

我也使用着名的Tank Auth库来管理用户,我使用了codeigniter Session类以在登录时存储和管理用户会话。每个用户可以指定他想要的界面语言并将其存储在数据库中以供将来登录。在每次登录时,将lang信息从DB复制到会话。

I am also using the famous Tank Auth library to manage users and I am using the codeigniter Session class to store and manage the users sessions upon log in. Each user can specify the interface language he wants and store it in the database for future log ins. The lang info is copied from the DB to the session on every log in.

问题是:我无法从挂钩内部检查用户会话。如果他的会话有lang信息,我怎么知道(如果登录的用户)?

The problem is: I can't check the user session from inside the hook. How would I know (in case of logged in users) if his session has the lang info or not?

我不知道钩子方法是最好的处理登录用户会话的情况。

I am not sure if the hook approach is the best one in case of handling logged in users sessions. Let me know please if I can have a better approach.

提前感谢

推荐答案

我通过使用 post_controller_constructor 钩子而不是 pre_controller 来解决这个问题。在该钩子中,会话是可访问的。所以我在CI会话中设置检测到的语言,并且我相应地加载语言文件。

I solved this by using a post_controller_constructor hook instead of pre_controller. In that hook, the session is accessible. So I am setting the detected lang in the CI session AND i am loading the language file accordingly.

我不知道这是否是最好的方法,但它工作正常如果你不在任何控制器构造函数中使用lang库。

I am not sure if this is the best approach, but it works fine if you are not using the lang library in any controller constructor.

这篇关于在预控制器codeigniter钩子中访问CI会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆