title: Setting Cookie variable in a Controller - Symfony2
body: <p>I'm trying to set a cookie in a Controller before rendering a twig file. After trying out a few suggestions i saw here, my code looks like below:</p>
  
  <pre><code>public function demandAction() {
  
      $result = array('message' =&gt; '');
      $response = $this-&gt;render('MainBundle:Default:demand.html.twig', $result);        
      $response-&gt;headers-&gt;setCookie(new Cookie('cookie', 'value', time() + 3600 * 24 * 7));
  
      return $response;
  }
  </code></pre>
  
  <p>But the cookie is not available in my rendered page when i alert document.cookie. I'm sure i must have missed something. Please help me out. Thanks.</p>