CodeIgniter:get_instance在My_Lang [英] CodeIgniter: get_instance inside My_Lang

查看:229
本文介绍了CodeIgniter:get_instance在My_Lang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个有用的国际化代码:

I found this useful Internationalization code:

http:// pastebin.com/SyKmPYTX

一切正常,除非我无法在此类中使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆