[英]Internationalised URLs with Codeigniter
I'm trying to add selected language code to the URL instead of storing it in a session or cookie . 我试图将选定的语言代码添加到URL中,而不是将其存储在会话或cookie中 。
My first time example below sets language manually but I want to make it dynamic based on user selection. 我在下面的第一个示例中手动设置语言,但是我想根据用户选择使其动态。 How can I produce links below?
我如何在下面产生链接?
I know that Codeigniter URLs works as base_url/class_name/function_name/parametters
我知道Codeigniter URL用作
base_url/class_name/function_name/parametters
Note: My base URL is : http://localhost/internationalisation/
注意: 我的基本URL是:
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 */
VIEW 视图
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.