我想通过创建文件CI_Lang
来扩展默认CodeIgniter的类/core/MY_Lang.php
,并且在该文件中我需要加载自定义配置文件:
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');
}
}
和/config/languages.php
自定义配置文件:
$config['languages'] = array(
'en' => 'english',
'fr' => 'french',
'ru' => 'russian',
'sk' => 'slovak'
);
每当我致电get_instance
时 - 我都会收到错误消息Fatal error: Class 'CI_Controller' not found in D:\wamp\www\ci2exp6\system\core\CodeIgniter.php on line 233
请有人澄清我的代码中有什么问题吗?
答案 0 :(得分:3)
在核心库中,您需要按如下方式调用它:
$CFG =& load_class('Config', 'core');
$CFG->load('languages', true);
$languages = $CFG->config['languages'];
$english = $languages['en'];
//etc...
应该这样做:)
更新了评论中的配置文件:
$config['en'] = 'english';
$config['fr'] = 'french';
$config['ru'] = 'russian';
$config['sk'] = 'slovak';