Php Codeigniter中的多语言
我使用框架代码点火器。 我已经写了一个库(类)翻译与数组字的四种语言Php Codeigniter中的多语言,php,codeigniter,Php,Codeigniter,我使用框架代码点火器。 我已经写了一个库(类)翻译与数组字的四种语言 class Translate { public function __construct(){ $this->CI =& get_instance(); $this->CI->load->library("countrylang"); $this->settings = $this->CI->countrylang->
class Translate
{
public function __construct(){
$this->CI =& get_instance();
$this->CI->load->library("countrylang");
$this->settings = $this->CI->countrylang->GetSettings();
$this->words = array(
'news feed' => array(20 => 'Leunta', 153 => 'Laita', 3 => 'News feed', 109 => 'Leuita'));
}
}
在控制器中,我加载此库:
$this->data['lang'] = $this->load->library('translate');
在我可以从视图
访问单词后,如下所示:
<?=$lang['news feed']?>
所以在helpers Codeigniter中,有一个单词必须在所选语言上替换并返回到视图
如何操作?如果要从帮助文件访问模型、库等,只需像在其他任何地方一样创建对全局CI对象的引用:
function someHelperFunction()
{
$CI =& get_instance();
$CI->load->library('somelibrary');
$CI->somelibrary->doSomething();
// ....
}
此行:
$This->data['lang']=$This->load->library('translate')代码>真的没有意义。加载程序的library方法只返回false或nullYes,这是一个很好的解决方案。真的没有一个好的替代方法。
function someHelperFunction()
{
$CI =& get_instance();
$CI->load->library('somelibrary');
$CI->somelibrary->doSomething();
// ....
}