user82324
user82324

Reputation: 79

CodeIgniter: get_instance inside My_Lang

I found this useful Internationalization code:

http://pastebin.com/SyKmPYTX

everything 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

Upvotes: 3

Views: 2780

Answers (2)

RednBlack
RednBlack

Reputation: 102

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.

Upvotes: 0

birderic
birderic

Reputation: 3765

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/

Upvotes: 2

Related Questions