2018-03-02 01:45
浏览 701


I need to create an app with multiple locales. And each route is prefixed with the locale. For example, xxx.com/en/home, xxx.com/fr/home.

The thing is, I need to dynamically bind the locale string to route prefix. Since users can change locale, the locale string is stored in session. And I need reference to the session on web.php. Session object can't be used in the globle scope on web.php, meaning session('key') won't get you anything (null) in the outermost scope except in route functions because Laravel parses web.php before instantiating any session object, I think. Therefore I face a conundrum in that I can't reference session in the outermost scope on web.php while I need session to create dynamic prefix. How can I solve this?

图片转代码服务由CSDN问答提供 功能建议

我需要创建一个包含多个区域设置的应用。 每个路由都以区域设置为前缀。 例如, xxx.com/en/home xxx.com/fr/home

事情是,我需要 动态绑定语言环境字符串到路由前缀。 由于用户可以更改区域设置,因此区域设置字符串存储在会话中。 我需要参考web.php上的会话。 Session对象不能在web.php的globle范围内使用,这意味着session('key')除了路由函数之外不会在最外层的范围内获取任何东西(null),因为Laravel在实例化任何会话之前解析web.php 对象,我想。 因此,我面临一个难题,即我不能在web.php的最外层范围内引用会话,而我需要会话来创建动态前缀。 我怎么解决这个问题?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题