在codeigniter中从multilang切换到默认lang

时间:2017-05-30 12:37:53

标签: codeigniter

我们正在使用像

这样的多语言网站
  

www.example.com/en/ www.example.com/es/

我们有这样的roout配置

$route['switch-language/language/(:any)'] = 'switch_language/language/$1';

$route['en/page/(:any)'] = 'page/view/$1';
$route['fr/page/(:any)'] = 'page/view/$1';
$route['es/page/(:any)'] = 'page/view/$1';
$route['pt/page/(:any)'] = 'page/view/$1';

我们有一个关闭语言切换器的可能性。当我们关闭网址时,我们仍然有www.example.com/en/格式。

关闭多重切换器时,是否有办法在网址上不显示语言标记?

语言切换器控件就像这样

class Switch_language extends CI_Controller {
    public function __construct() {
        parent::__construct ();
    }
    function language($language = "") {
        $this->load->model('template_model', '', TRUE);

        $language = ($language != "") ? $language : "english";
        $this->session->set_userdata ( 'site_lang', $language );

        $language_iso = $this->template_model->get_language_iso2_from_language_key($language);
        $this->session->set_userdata('site_lang_iso', strtolower($language_iso));

        //redirect ( base_url () );
        if(isset($_SERVER["HTTP_REFERER"])){
            //redirect($_SERVER["HTTP_REFERER"]);
            redirect ( base_url ().strtolower($language_iso) );
        }
        else{
            redirect ( base_url () );
        }
    }
    function language_code() {
        if ($this->input->post ( 'language_save' )) {
            $this->load->model('template_model', '', TRUE);
            $language = $this->input->post ( 'language_key' );

            $language = ($language != "") ? $language : "english";
            $this->session->set_userdata ( 'site_lang', $language );

            $language_iso = $this->template_model->get_language_iso2_from_language_key($language);
            $this->session->set_userdata('site_lang_iso', strtolower($language_iso));

            //redirect ( base_url () );
            if(isset($_SERVER["HTTP_REFERER"])){
                //redirect($_SERVER["HTTP_REFERER"]);
                redirect ( base_url ().strtolower($language_iso) );
            }
            else{
                redirect ( base_url () );
            }
        }
    }
}

当我手动从路线中删除lang标签时没问题。但是需要一些自动的东西。

关闭路线时

$route['page/(:any)'] = 'page/view/$1';

需要一些逻辑来解决这个问题。

0 个答案:

没有答案