Reputation: 2567
I try to add array of multiple vals to session var bu sending ajax request. I do this:
public function addFoodAction(Request $request)
{
$foodId = json_decode($request->getContent(), true)['food'];
$food = $this->getDoctrine()->getRepository('HackatonDinningRoomBundle:Food')->find($foodId);
$arr = array();
$arr[]=$food;
$session = $this->get('session');
$session->set('items', array($food));
return new Response(count($arr));
}
How I can do that ?
Upvotes: 0
Views: 361
Reputation: 5133
Use serialize
:
$session->set('items', serialize(array($food)));
To retrieve the data:
unserialize($session->get('items'));
Upvotes: 3