title: Symfony2 Cookies not being set in controller
body: <p>I can't seem to get cookies set from my controller.</p>
  
  <p>code:</p>
  
  <pre><code>/**
       * @Route("", name="wx_exchange_default_index")
       * @Template("WXExchangeBundle:Default:index.html.twig")
       * @Method({"GET"})
       */
      public function indexAction(Request $request)
      {
          $returnArray['parents'] = self::getCategories();
          $cookieLocationSession = $request-&gt;cookies-&gt;get('locationidsession', 0);
          $cookieLocation = $request-&gt;cookies-&gt;get('locationid', 0);
          $securityContext = $this-&gt;container-&gt;get('security.context');
          $hashids = $this-&gt;get("wxexchange_hashids_service");
  
          if ($securityContext-&gt;isGranted('IS_AUTHENTICATED_REMEMBERED'))
          {
              $user = $securityContext-&gt;getToken()-&gt;getUser();
              $returnArray['user'] = $user;
              $location = $user-&gt;getTblProfile()-&gt;getTblLocation();
  
              if(!$cookieLocation || $cookieLocation != $hashids-&gt;encrypt($location-&gt;getId()))
              {
                  $cookieLocation = $hashids-&gt;encrypt($location-&gt;getId());
  
                  //TODO: cookies are not being set figure out whys
                  $response = new Response();
                  $response-&gt;headers-&gt;setCookie(new Cookie("locationid", $cookieLocation, 365, '/', null, false, false));
                  $response-&gt;sendHeaders();
              }
          }
  
          if (!$cookieLocation &amp;&amp; !$cookieLocationSession)
          {
              return $returnArray;
          }
  
          if ($cookieLocationSession)
          {
              $cookieLocation = $cookieLocationSession;
          }
  
          if (!isset($location) || $cookieLocationSession)
          {
              $locationService = $this-&gt;get("wxexchange_location_service");
              $locationId = $hashids-&gt;decrypt($cookieLocation);
              if(count($locationId) &gt;= 1)
                  $location = $locationService-&gt;getLocationById($locationId[0]);
          }
  
          if(isset($location))
              return $this-&gt;redirect($this-&gt;generateUrl('wx_exchange_location', array('slug' =&gt; $location-&gt;getSlug(), 'locationid' =&gt; $cookieLocation)));
  
  
          return $returnArray;
      }
  </code></pre>
  
  <p>Do I have to return the response? If I do how do I keep processing (I have a redirect further down in my code)?</p>
  
  <p><strong>Edit:</strong> Interestingly enough if the same cookie is already set (via JQuery) running the code above deletes it, but it won't set it.</p>
  
  <p><strong>Edit:</strong> Action code posted.</p>