Reputation: 214
I have a website ( https://wtf.az/ ), but when I want to change the language it refreshes the page but does not change on the first attempt. However, when I click on another URL it changes the language. Also, this problem occurs when I want to log in. Where can be the problem? Here is the controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class LanguageSwitcher extends CI_Controller
{
public function __construct() {
parent::__construct();
}
function switchLang($language = "") {
$language = ($language != "") ? $language : "azerbaijani";
$this->session->set_userdata('site_lang', $language);
redirect($_SERVER['HTTP_REFERER']);
}
}
Here is my hook:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class LanguageLoader
{
function initialize() {
$ci =& get_instance();
$ci->load->helper('language');
$siteLang = $ci->session->userdata('site_lang');
if ($siteLang) {
$ci->lang->load('header',$siteLang);
$ci->lang->load('footer',$siteLang);
$ci->lang->load('index',$siteLang);
} else {
$ci->lang->load('header','azerbaijani');
$ci->lang->load('footer','azerbaijani');
$ci->lang->load('index','azerbaijani');
}
}
}
I have changed $config['sess_save_path'] = NULL;
to $config['sess_save_path'] = BASEPATH . 'cache/';
. Can it cause this problem?
Upvotes: 0
Views: 39
Reputation: 956
Change
redirect($_SERVER['HTTP_REFERER']);
to
redirect(base_url());
and add $this->load->helper('url');
to the Constructor.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Languageswitcher extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->helper('url');
}
function switchLang($language = "") {
$language = ($language != "") ? $language : "azerbaijani";
$this->session->set_userdata('site_lang', $language);
redirect(base_url());
}
}
Upvotes: 2