CodeIgniter:get_instance在My_Lang [英] CodeIgniter: get_instance inside My_Lang
问题描述
我发现这个有用的国际化代码:
I found this useful Internationalization code:
一切正常,除非我无法在此类中使用CI函数。
everything works well except I am unable to use CI functions inside this class .
我想从DB设置$ languages和$ special变量。
I want to set $languages and $special variable from DB .
但是当我使用$ CI =& get_instance();在实例函数中显示以下错误:
but when I am using $CI =& get_instance(); in instance function its showing following error :
致命错误:在第231行的/system/core/CodeIgniter.php中未找到类'CI_Controller'
Fatal error: Class 'CI_Controller' not found in /system/core/CodeIgniter.php on line 231
推荐答案
语言类在CodeIgniter实例存在之前加载,这就是为什么你会得到错误。
The language class is loaded before the CodeIgniter instance exists, which is why you get the error.
您可以使用 post_controller_constructor 钩子设置您的变量。
You can use a post_controller_constructor hook to set your variables.
这里是来自CodeIgniter论坛的线程,其中有人试图做类似的事情: http://codeigniter.com/forums/viewthread/108639/
Here is a thread from the CodeIgniter forums where someone is tried to do something similar: http://codeigniter.com/forums/viewthread/108639/
这篇关于CodeIgniter:get_instance在My_Lang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!