This is my code in controller.php
if(!isset(Yii::app()->session['cart_values'])) {
Yii::app()->session['cart_values'] = array();
}
$sessionCart = array();
$sessionCart[] = array('product_id' => Yii::app()->session['productID'], 'document' => Yii::app()->session['productName']);
Yii::app()->session['cart_values'] = $sessionCart;
My problem is that when I try to echo the result I got only the last record that I have selected, but what I need is every record selected in this session. I know that i need to make a check before I start to filing the array, but not sure how.
<?php
if (is_array(Yii::app()->session['cart_values']))
{
foreach ( Yii::app()->session['cart_values'] as $value) {
echo $value['document'];
}
}
?>
I want to understand it by my own, but i'm confused,so if anybody could help me I would be very happy. Thanks.
PS Sorry for my English, i hope everybody understands me.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I get my solution by my own, thanks everybody, so my controller php script should look like this.
if(!isset(Yii::app()->session['cart_values'])) {
Yii::app()->session['cart_values'] = array();
} else {
$sessionCart = Yii::app()->session['cart_values'];
$sessionCart[] = array('product_id' => Yii::app()->session['productID'], 'document' => Yii::app()->session['productName']);
Yii::app()->session['cart_values'] = $sessionCart;
}
这是你想要的?
Yii::app()->session['cart_values'][] = $sessionCart;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.