使用Codeigniter的国际化URL

时间:2012-10-25 16:09:49

标签: php codeigniter

我正在尝试将选定的语言代码添加到网址,而不是将其存储在会话 Cookie 中。

下面我的第一次示例手动设置语言,但我想根据用户选择使其动态化。我如何在下面制作链接?

我知道Codeigniter网址的工作方式为base_url/class_name/function_name/parametters

注意: 我的基本网址是:http://localhost/internationalisation/

http://localhost/internationalisation/en/
http://localhost/internationalisation/en/welcome
http://localhost/internationalisation/en/products/1
http://localhost/internationalisation/en/products/2
http://localhost/internationalisation/en/aboutus
http://localhost/internationalisation/en/contactus
OR spanish version

CONTROLLER

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load->helper('url');

        //$this->lang->load('en', 'english');
        $this->lang->load('es', 'spanish');
    }

    public function index()
    {
        $this->load->view('welcome_message');
    }
}

/* EoF */

查看

<a href="<?php echo site_url('en'); ?>">English</a>
<br />
<a href="<?php echo site_url(); ?>es">Spanish</a>

<br /><br /><br /><br />

<h1><?php echo $this->lang->line('welcome'); ?></h1>

1 个答案:

答案 0 :(得分:0)

您应该在Wiki搜索此类内容,例如此库URI Language Identifier可以执行您想要的操作。

相关问题