title: Read and Write Cookie in Symfony2
body: <p>I want to store some information in the local browser cookie. After hours looking for a nice tutorial, I managed to store some data in a non-session cookie:</p>
  
  <p><strong>controller - indexAction()</strong></p>
  
  <pre><code>$cookieGuest = array(
      'name'  =&gt; 'mycookie',
      'value' =&gt; 'testval',
      'path'  =&gt; $this-&gt;generateUrl('my_route'),
      'time'  =&gt; time() + 3600 * 24 * 7
  );
  
  $cookie = new Cookie($cookieGuest['name'], $cookieGuest['value'], $cookieGuest['time'], $cookieGuest['path']);
  
  $response = new Response();
  $response-&gt;headers-&gt;setCookie($cookie);
  $response-&gt;send();
  </code></pre>
  
  <p>I wonder if this is the correct way. Furthermore I tried several ways to read the cookie with the HttpFoundation Component, but without success. Is there another way than accessing the cookie via <strong>$_COOKIE['mycookie']</strong> ?</p>
  
  <p>Here is where I try to read the cookie</p>
  
  <p><strong>controller - cookieAction()</strong></p>
  
  <pre><code>public function cookieAction($_locale, $branch, $page) 
  {   
      $response = new Response();
      $cookies = $response-&gt;headers-&gt;getCookies();
  
      var_dump($cookies);
  
  // TODO: Get params for indexAction from cookie if available
  
      return $this-&gt;indexAction($_locale, $branch, $page);
  }
  </code></pre>