我需要这样:
$_SESSION['key']['subkey1'] = 'value1';
$_SESSION['key']['subkey2'] = 'value2';
如果我以Yii的方式做,我收到一个错误:
Indirect modification of overloaded element of CHttpSession has no effect
Yii::app()->session['key']['subkey1'] = 'value1';
Yii::app()->session['key']['subkey2'] = 'value2';
我可能会这样做:
Yii::app()->session['key'] = array('subkey1' => 'value1', 'subkey2' => 'value2')
这没关系,但问题仍然是我无法修改值
Yii::app()->session['key']['subkey2'] = 'value3';
有什么想法吗?使用$ _SESSION和Yii :: app() - > session?
实际上有什么区别吗?答案 0 :(得分:1)
尝试这样的事情
$temp = Yii::app()->session;
$temp['key']['subkey1'] = 'value1';
$temp['key']['subkey2'] = 'value2';
Yii::app()->session = $temp;
这是重载错误的解决方法。
您无法直接修改重载元素,因为它们并不像属性那样存在。你可以在这里读更多关于它的内容: http://php.net/manual/en/language.oop5.overloading.php
您可以在此处详细了解$ _SESSION与Yii :: app() - >会话之间的差异: http://www.larryullman.com/2011/05/03/using-sessions-with-the-yii-framework/