Codeigniter多语言-从ajax中选择-会话问题
我想制作多语言网站并使用ajax选择语言,将从数据库中选择不同的单词,我想使用session[lang],并且我不想使用GET[lang]。 我花了 5 天的时间来尝试做这个,但我尝试了很多变体,现在我很困惑,
我在这里:
我有模型 -> Langs ->
function set_langs($arg) {
$this->session->unset_userdata(‘lang’);
$this->session->set_userdata(‘lang’, $arg);
return $arg;
}
function get_langs() {
return $this->session->userdata(‘lang’);
}
在 Home 控制器 ->
public function index(){
if($this->session->userdata(‘lang’)==’‘){
$this->Langs->set_langs(‘en’);
$glang[‘lang’] = $this->Langs->get_langs();
}else{
$glang[‘lang’] = $this->Langs->get_langs();
}
$this->load->view(‘header’, $glang);
}
public function set()
{
if($_POST && $_POST[‘lang’] != NULL) {
$this->Langs->set_langs($_POST[‘lang’]);
$return[‘error’] = false;
$return[‘msg’] = $this->session->userdata(‘lang’).’ ok!’;
echo json_encode($return);
}else{...}
}
和 header.php -> 中在 JS 中 ->
$.ajax({
type: “POST”,
url: “index.php/home/set”,
dataType : ‘json’,
data: “lang=”+lang,
success: function(data){
if(data.error === true){
$( “#dialog-message2” ).text(data.msg).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( “close” );[removed]=location.href;
}
}
});
}else{...}
当页面刷新时语言仍然没有改变,但是当从 ajax 返回消息时它可以工作 所以我哪里错了 抱歉英语不好 谢谢
*问题是 -> system/libraries/Session.php(来自 CodeIgniter_2.0.2.zip 的原始文件)->我下载http://codeigniter.com/wiki/File:CI_1.5.1_with_Session。 zip/ 没有问题
i want to make the site with multi languages and selecting the language with ajax and the different words will be selected from database and i want to use session[lang],and i don’t want to use GET[lang].
i’m trying from 5 days to make this but i try so many variants and i’m confused now
now i’m here:
i have model -> Langs ->
function set_langs($arg) {
$this->session->unset_userdata(‘lang’);
$this->session->set_userdata(‘lang’, $arg);
return $arg;
}
function get_langs() {
return $this->session->userdata(‘lang’);
}
in the Home controller ->
public function index(){
if($this->session->userdata(‘lang’)==’‘){
$this->Langs->set_langs(‘en’);
$glang[‘lang’] = $this->Langs->get_langs();
}else{
$glang[‘lang’] = $this->Langs->get_langs();
}
$this->load->view(‘header’, $glang);
}
public function set()
{
if($_POST && $_POST[‘lang’] != NULL) {
$this->Langs->set_langs($_POST[‘lang’]);
$return[‘error’] = false;
$return[‘msg’] = $this->session->userdata(‘lang’).’ ok!’;
echo json_encode($return);
}else{...}
}
and in the header.php -> in the JS ->
$.ajax({
type: “POST”,
url: “index.php/home/set”,
dataType : ‘json’,
data: “lang=”+lang,
success: function(data){
if(data.error === true){
$( “#dialog-message2” ).text(data.msg).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( “close” );[removed]=location.href;
}
}
});
}else{...}
when the page refresh the language stil not changed but when return the message from ajax it work
so where im wrong
sorry for the bad english
thanks
* the problem was -> system/libraries/Session.php (the original file from the CodeIgniter_2.0.2.zip) -> i download http://codeigniter.com/wiki/File:CI_1.5.1_with_Session.zip/ and no problems
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)