doushi9729 2013-01-18 09:46
浏览 33
已采纳

PHP和从任何地方访问全局对象

I have a global object, a "registry", it is a container with other important objects:

  • Input object.
  • Output object.
  • DB object with connection.
  • Logging object.
  • Session object.

I need to have this global object in every place (object), where I process my request.

Like in my JBoss environment, where I have one Stateful Session Bean as a front controller, which directs the processing to a special Stateless Session Bean, I have one entry point, "facade.php".

In this facade.php, I create the global object and place the other objects (input object, ...) into it.

Then there is a large switch statement, where I redirect the request to special processing objects.

Is there a method, mechanism, to have access to this general object from the processing objects without handing it over as a parameter?

  • 写回答

2条回答 默认 最新

  • duanhemou9834 2013-01-18 09:49
    关注

    To have a variable available everywhere you can use a $_SESSION variable like so:

    session_start();
    $_SESSION['registry'] = // Your data
    

    Make sure to use the session_start() function whenever you want access to the session variables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线