CodeIgniter 变量在我的应用程序中可用吗?
Possible Duplicate:
Best way to setup a variable for Global use in CodeIgniter?
I have meta data about the user that will constantly change therefore I dont want to store it a session.
It would also need to be available throughout my application.
How would I go about doing this?
Thanks in advance.
Sean Jenkins
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能希望尝试使用 codeigniter 的 MY_Controller:
Codeigniter |我的控制器
它位于名为 MY_Controller.php 的“核心”文件夹中。然后,您将
在所有控制器中调用 MY_Controller 而不是 CI_Controller。
然后,您可以
从应用程序中的任何位置调用。
You may wish to try using codeigniter's MY_Controller:
Codeigniter | MY Controller
This is placed in the 'core' folder called MY_Controller.php. You would then call
MY_Controller instead of CI_Controller in all of your controllers.
You can then call
From anywhere within your application.
编辑:我刚刚阅读了您的其他问题。我想这个解决方案不是您正在寻找的。
您可以将其存储在库中(例如
mylib
),并将该库添加到 application/config/autoload.php 中的自动加载:$autoload['libraries'] = array('mylib ');
然后您可以加载此库并在应用程序中的任何位置访问该变量:
$this->load->library('mylib');
echo $this->mylib->my_variable;
Edit: I've just read your other question. I guess this solution is not what you're looking for.
You can store it in a library (for example,
mylib
) and add this library to autoload in application/config/autoload.php:$autoload['libraries'] = array('mylib');
Then you can load this library and access the variable anywhere in your application:
$this->load->library('mylib');
echo $this->mylib->my_variable;