Google Groups

SetCookie help


Michael Apr 28, 2012 5:44 PM
Posted in group: Symfony developers (DISABLED)
I'm trying to set a cookie for an embedded controller but can't seem
to make it work. Can someone help me with it? Here is what I have:

// in twig page
{% render "ACMEDemoBundle:Main:cookie" %}

// in controller
public function cookieAction()
{
    if (in_array('cookietest', $this->get('request')->get('cookies'))
{
        return new Response();
    }

    $response = $this->render('ACMEDemoBundle:Main:intro.html.twig');
    $response->headers->setCookie(new Cookie('cookietest', 'true',
time() + 60 * 60 * 24 * 30));
    return $response;
}