セッションまたはCookieに保存する代わりに、選択した言語コードを URL に追加しようとしています。
以下の最初の例では、言語を手動で設定しますが、ユーザーの選択に基づいて動的にしたいと考えています。以下のリンクを作成するにはどうすればよいですか?
Codeigniter URL が次のように機能することを知っていますbase_url/class_name/function_name/parametters
注: 私のベース 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
コントローラ
<?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>