update session variable in yii [duplicate]

守給你的承諾、 提交于 2019-12-25 11:13:41

问题


I want to know how can i update my session variable, in my controller, when i am on page1, in my public function actionpage1() i have this code

$quantity=1;
$sessionCart[] = array('product_id' => $_POST['documents'], 'document' => $productInfo->name, quantity'=> $quantity);

so my default quantity is 1,

And when i go to another page page2, and click on update button,

I want my $quantity to be equal to $_post['quantity'] my new valule, (this is <?php echo CHtml::textField('quantity', $value['quantity']); ?>)


回答1:


You can store session data with:

Yii::app()->user->setState('key', 'value');

and get it with:

Yii::app()->user->getState('key');



回答2:


Use this:-

Yii::app()->session['name'] = $value



回答3:


in your form field:

CHtml::textField('quantity', $value['quantity']);

the value must be retrieved from session array variable but not from the passed static variable: Replace value like this:

CHtml::textField('quantity', sessionCart['quantity']);


来源:https://stackoverflow.com/questions/17105660/update-session-variable-in-yii

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