php session issue in remove value from Cart Sessin Array -


i using yii framework , unable remove value session. when call function using ajax, error in console

indirect modification of overloaded element of chttpsession has no effect

any suggestion helpful in advance . below code

public function actiondeleteproductajax() {     $session = yii::app()->session;     $id = isset($_post['id']) ? $_post['id'] : "";     $key = array_search($id, $session['cart_items']);     if ($key !== false) {         unset($session['cart_items'][$key]);         echo 'success';     } } 

i want remove index of array because value containt similar ids of products added more 1 time

try this:

$cartitems = yii::app()->session['cart_items']; $id = isset($_post['id']) ? $_post['id'] : ""; $key = array_search($id, $cartitems); if ($key !== false) {     unset($cartitems[$key]);     echo 'success'; } yii::app()->session['cart_items'] = $cartitems; 

you cannot directly modify session item, internally handled yii getters , setters, unset() have no effect, hence warning. can unset item in copy $cartitems , assign remaining array session object.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

methods - python can't use function in submodule -

c# - ErrorThe type or namespace name 'AxWMPLib' could not be found (are you missing a using directive or an assembly reference?) -