开发者

CodeIgniter: get_instance inside My_Lang

I found this useful Internationalization code:

http://pastebin.com/SyKmPYTX

everything开发者_如何学Python works well except I am unable to use CI functions inside this class .

I want to set $languages and $special variable from DB .

but when I am using $CI =& get_instance(); in instance function its showing following error :

Fatal error: Class 'CI_Controller' not found in /system/core/CodeIgniter.php on line 231


The language class is loaded before the CodeIgniter instance exists, which is why you get the error.

You can use a post_controller_constructor hook to set your variables.

Here is a thread from the CodeIgniter forums where someone is tried to do something similar: http://codeigniter.com/forums/viewthread/108639/


The easiest way

in My_Lang.php

var $languages = array();

function __construct()
{
parent::__construct();

require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$query = $db->query( 'SELECT * FROM languages');
$result = $query->result();

foreach( $result as $row )
{
$this->languages[$row->short_name] = $row->full_name;
}
}

i did this and is working fine :)) i also added default_uri in foreach.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜