Yii - Manipulating a sesssion variable

和自甴很熟 提交于 2019-12-02 09:54:48

I personally I have never used Yii::app()->session I normally use the Yii user and I have never had any issues with it:

Yii::app()->user->setState('test', array('a'=>1,'b'=>2));
print_r(Yii::app()->user->getState('test')); //see whole array

$test = Yii::app()->user->getState('test');
unset($test['b']);
Yii::app()->user->setState('test',$test);
print_r(Yii::app()->user->getState('test')); //only 'a'=>1 remains

Yii::app()->user->setState('test', null);
print_r(Yii::app()->user->getState('test')); //now a null value

As I put in a comment above there seems to be issues with multidimensional arrays with the session variable: https://code.google.com/p/yii/issues/detail?id=1681

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!