Reputation: 3937
I want to extend default CodeIgniter's class CI_Lang
by creating a file /core/MY_Lang.php
, and inside that file I need to load a custom configuration file:
class MY_Lang extends CI_Lang {
var $CI;
// Default langs
var $languages = array(
'en' => 'english',
'fr' => 'french'
);
public function __construct(){
parent::__construct();
global $CFG;
$this->CI =& get_instance(); // NOT WORKING
// Load custom config file from /config/languages.php
$this->languages = $this->CI->config->item('languages');
}
}
and /config/languages.php
custom config file:
$config['languages'] = array(
'en' => 'english',
'fr' => 'french',
'ru' => 'russian',
'sk' => 'slovak'
);
Whenever I call for get_instance
- I get an error telling me Fatal error: Class 'CI_Controller' not found in D:\wamp\www\ci2exp6\system\core\CodeIgniter.php on line 233
Please, could someone clarify what's wrong in my code ?
Upvotes: 0
Views: 2741
Reputation: 2391
Inside of a core library you need to call it as follows:
$CFG =& load_class('Config', 'core');
$CFG->load('languages', true);
$languages = $CFG->config['languages'];
$english = $languages['en'];
//etc...
That should do the trick :)
Updated config file from comment:
$config['en'] = 'english';
$config['fr'] = 'french';
$config['ru'] = 'russian';
$config['sk'] = 'slovak';
Upvotes: 4