Indirect modification of overloaded element of CHttpSession has no effect
{Boy Said}
我们可以使用$_SESSION['YiiLib']['Lee']来存储PHP Session, 但是在Yii中有所不同, 应当遵循如下的模式.
{Code - 不正确 }
$defaultLabels = XXX::model()->findAllByAttributes(array('yiilib_fbPageId' => $pageId, 'yiilib_locale_id' => $userLanguage->l_id));
foreach ($defaultLabels as $defaultLabel) {
Yii::app()->session['YiiLib'][$defaultLabel->yiilib_ident] = $defaultLabel->yiilib_value;
}
如果在Yii中使用上面的代码会得到错误提示 "Indirect modification of overloaded element of CHttpSession has no effect", 主要原因是 CHttpSession 不支持像 ['YiiLib']['Lee']这样的index.
{Code - 正确}
$defaultLabels = XXX::model()->findAllByAttributes(array('yiilib_fbPageId' => $pageId, 'yiilib_locale_id' => $userLanguage->l_id));
foreach ($defaultLabels as $defaultLabel) {
$localeArray[$defaultLabel->yiilib_ident] = $defaultLabel->yiilib_value;
}
Yii::app()->session['YiiLib'] = $localeArray;
留言