我有以下代码来识别language_id的会话,或者如果传递$ _GET变量,则设置会话。在detectLanguage()
init();
private function detectLanguage()
{
if(isset($_GET['language_code']) && !empty($_GET['language_code'])){
$language = Language::model()->find(array(
'condition' => 'iso_code = :iso_code',
'params' => array(':iso_code' => $_GET['language_code']),
));
if($language != NULL){
Yii::app()->session['language_id'] = $language->id;
$this->redirect(Yii::app()->request->urlReferrer);
} else {
$this->redirect(Yii::app()->request->urlReferrer);
}
} else {
$currentLang = (isset(Yii::app()->session['language_id']))? Yii::app()->session['language_id'] : 1;
if(Language::model()->find(array('condition' => "id = :id AND country_id = :country_id",'params' => array(':id' => $currentLang, 'country_id' => $this->country_details['ID'])))){
return $currentLang;
} else {
Yii::app()->session['language_id'] = 1;
return 1;
}
}
}
当我转到URL ...?language_code = ru时,它成功设置会话并重定向到引荐来源网址,但是当我刷新页面时,它会将language_id会话重置为1.
我不明白,据我所知,我在这个功能中的逻辑很好。
编辑:还尝试使用cookie,并且没有其他代码与这些SESSION变量交互,这可能是干扰。