问题
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