title: How to set cookie in a CakePHP dispatcher filter?
body: <p>In my application I need do some kind of "auto login" logic at the beginning of app work. In this "auto login" function I do many actions, and one of them - setting cookie, using CookieComponent.</p>
  
  <p>When I use this autoLogin in controller or component - all is fine, BUT cookies are NOT set when I do the same from dispatcher filter.</p>
  
  <p>I dig deep into CakePHP code, and found that when I try set cookie from dispatcher filter, <code>$_cookies</code> property of <code>CakeResponse</code> are empty. So it's looks like dispatcher filter creates own <code>CakeResponse</code>, and it resets later, so cookie are not set.</p>
  
  <p>My filter looks like this: </p>
  
  <pre><code>class UserLoadFilter extends DispatcherFilter 
  {
      public $priority = 8;    
      public function beforeDispatch($event) {
          App::uses('AuthComponent', 'Controller/Component');
          if (!AuthComponent::user()) {
              App::uses('CustomAuthComponent', 'Controller/Component');
              //$controller = new AppController($event-&gt;data['request'], $event-&gt;data['response']);
              $auth = new CustomAuthComponent(new ComponentCollection(), Configure::read('Auth'));
              $auth-&gt;autoLogin();
          }
      }
  }
  </code></pre>
  
  <p>I also tried set cookie directly in beforeDispatch method in this way:</p>
  
  <pre><code>App::uses('CookieComponent', 'Controller/Component');
  $cookie = new CookieComponent(new ComponentCollection());
  $cookie-&gt;write('test', 'TEST!', false, "1 day"); 
  </code></pre>
  
  <p>but this has no sense too.</p>
  
  <p>What do I do wrong? Maybe I just don't see some simple things, but I spent many time and still can't fix this. Is it's possible at all to set cookie from this place?</p>
  
  <p>Sure I can try just use setcookie, or write own cookie wraper, but I want to do it in CakePHP style, using cookie component.</p>