How to attach cookies to JSON Response in symfony2?

Viewed 5066

I have JSON endpoint which is used to add product to cart. It checks whether the cart already exists or no. If not then it creates a cart and the cart Id is stored in cookie. So I how do I attach cookie to the symfony2's JsonResponse ?

In a non ajax version if I am rendering a template from my action I can use:

$response = new Response();
$response->headers->setCookie(new Cookie(‘cookie_name’, ‘cookie_value’));

$this->render('<template_path>', '<array_options>', $response);

Please help me on how to do it for a JsonResponse.

1 Answers
Related