[eluser]chris1986m[/eluser]
Hi,
i have a problem with my language switch.
Its a simple language switch. Only two buttons which calls the languageSwitch Method and refresh the page.
The Problem is, that the session variable is written after the second click on the Button. On the first click, the page makes a reload and the default language is selected, not the clicked one.
After the second click, everythink works fine! I have to click twice on the first time. After this, the language is change on every click!
Thanks for all your help!
The the links:
/start/languageSwitch/de
/start/languageSwitch/en
Here my simple code
Code:
$autoload['libraries'] = array('session', 'user_agent');
$autoload['language'] = array();
$config['language'] = 'de';
Code:
class Start extends CI_Controller {
public function index() {
$this->load->helper('url');
$this->load->helper('language');
$this->lang->load('main', $this->session->userdata('language'));
//Check language
if (!$this->session->userdata('language'))
$this->session->set_userdata('language','de');
//Check mobile version
if ($this->agent->mobile())
$this->load->view('mobile');
else
$this->load->view('index');
}
public function languageSwitch() {
$this->load->helper('url');
$this->load->helper('language');
$this->lang->load('main', $this->session->userdata('language'));
$this->session->set_userdata('language',$this->uri->segment(3));
redirect('http://www.test.de/','refresh');
}
}
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]