图书馆
class getLang {
public function getText($en, $ar) {
$CI =& get_instance();
$lang = $CI->session->userdata('language');
if ($lang == 'en') {
$string = $en;
} else if ($lang == 'ar') {
if (!empty($ar)) {
$string = $ar;
} else if (empty ($ar)) {
$string = $en;
}
}
return $string;
}
}
控制器
class Home extends MY_Controller {
public function test() {
$this->load->library('getLang');
return $this->getLang->getText('text', '');
}
}
当我运行 home/test 时,我收到此错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Home::$getLang
Filename: controllers/home.php
Line Number: 6
我已经在 config/autoload 中加载了自定义库。看起来库没有加载,我也尝试在控制器中加载它,仍然无法正常工作!我该如何解决这个问题?