2

I use the following code to pass an array to session:

$app = JFactory::getApplication();
$input = $app->input;
$itemid = $input->get('id');
$quan = $input->get('quan');
$session = JFactory::getSession();
$cart = array();
$cart['items'][] = array('id' => $itemid, 'quan' => $quan);
$session->set('cart', $cart);

It passes data of one item successfully, but when I try to add one more item to the session the code doesn't add it as a new item but overwrites existed item by new item. How to resolve the problem?

1

Just get your existing data from session, modify it and push it back into the session.

Replace

$cart = array();

with

$cart = $session->get('cart', array());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.