[CodeIgniter] 在自定义类库中使用config配置项

通常情况下,Controller 中的方法可以通过 $this->config->item('item_name') 的方式来加载配置文件中的值
但是如果不继承 CI_Controller 这个方式就不能用了

这时候可以通过创建来自 CI_Controller 的引用来实现:

$CI =& get_instance();
$item_value = $CI->config->item('item_name');

详见官方文档:

在你的类库中使用 CodeIgniter 资源
http://codeigniter.org.cn/user_guide/general/creating_libraries.html#codeigniter

posted @ 2017-01-04 10:52  风在山路吹  阅读(1048)  评论(0编辑  收藏  举报