I working on bookstore project, I have a list of books with button Add to Cart , click on that should save the ID of book in session by some name. But problem for me is how can save many this ID inside session so I can later access them inside foreach?
/**
* @Route("/cart/{bookId}", name="AppBundle_Book_addingToCartAction")
*/
public function addingToCartAction(Request $request, int $bookId)
{
// getting session
$sessionCart = $request->getSession();
// when user click on button Add to Cart , i send ID of book here(and others book IDs),
// so i need to save that ID inside a session(i was thinking making of some array
// with all this values), so how can I do this,i trying like this:
$sessionCart->set('BookIDs', array('Book'.$bookId => $bookId));
return $this->render('AppBundle:Books:shopingCart.html.twig', array(
'id' => $bookId,
));
}