dtc88867 2014-01-04 02:10
浏览 48
已采纳

在Laravel 4应用程序配置期间使用Session类

Is it possible to access the Session class in my app/config/app.php file?

I am able to use use Illuminate\Support\Facades\Input; but not use Illuminate\Support\Facades\Session; (or Cookie for that matter) at this stage of the app request.

I think it may be a good way to store my debug toggle for my development environment. I will toggle debug via a GET variable and would like it to last throughout a session (or until I unset it), rather than until the next request which will not include the variable.

  • 写回答

1条回答 默认 最新

  • doupu3211 2014-01-04 09:24
    关注

    The contig files are loaded very early in the app's lifetime, I'm surprised even Input works. No, there is no way to use session variables in the config files themselves. You could use an app event to change the config values at runtime, App::booting should be appropriate for this. In app/start/global.php:

    App::booting(function() {
        if (Session::get(...)) Config::set(...);
    });
    

    Note that this may not always have the results you expect. For example, as soon as the app is started, it checks the config for app.debug == true and chooses its exception handler accordingly, so if you'd want to change the exception handler after the app has started, you'd have to do it directly via app('exception')->setDebug(true). There may be any number of similar configurations you need to do, depending on your setup.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元