我有一个表在我的数据库中,我从那里得到一些文本:
- art_and_culture
- business_and_financial
- auto_and_moto
并通过
显示在我的网站上<?php echo lang($slug_from_database); ?>
我使用这个方法作为LanguageSwticher:
multi-language-support-in-codeigniter
在my_controller。php中,我写入in construct:
$this->categories_list = $this->categories_model->entries();
$list_categories['categories'] = $this->categories_list;
$this->data['sidebar_categories'] = $this->load->view('blocks/sidebar_categories', $list_categories, TRUE);
和所有类别都可以从我的网站的所有页面。问题是,当我发送到视图的类别,语言不是从LanguageLoader.php控制器设置,而是在hooks.php中初始化(见链接示例)。如果没有语言,在echo $slug_from_database上没有文本。你建议怎么做?
我找到了一个解决方案:
创建:
public function LanguageLoader() {
$site_lang = $this->session->userdata('site_lang');
if ($site_lang) {
$this->lang->load('message',$this->session->userdata('site_lang'));
} else {
$this->lang->load('message', $this->config->item('language'));
}
}
在MY_Controller.php $this->LanguageLoader();
和delete
$hook['post_controller_constructor'] = array(
'class' => 'LanguageLoader',
'function' => 'initialize',
'filename' => 'LanguageLoader.php',
'filepath' => 'hooks'
);
from hooks。php现在我在控制器的结构中加载语言而不是通过hook。