title: cakephp auth->loginRedirect for admin
body: <p>I'm fairly new to cakePHP and have read all the tutorials on the cake site. I'm building a small sample app using cake 2.1 and have hit a problem. Basically, I want admin users redirected to a different page on login than what a normal user gets redirected to. I'm sure there's an easy way to do this but I'm struggling!</p>
  
  <p>I have Admin routing enabled and am using the auth component (and the ACL component though that's not affecting my issue). I have 2 logins one for admin - admin_login() and a login for normal users  - login() - the normal non admin login works fine.</p>
  
  <p>In my AppController.php I have this:</p>
  
  <pre><code>class AppController extends Controller {
  
  public $components = array(
      'Acl',
      'Auth' =&gt; array(
          'authorize' =&gt; array(
              'Actions' =&gt; array('actionPath' =&gt; 'controllers')
          )
      ),
      'Session'
  );
  public $helpers = array('Html', 'Form', 'Session');
  
  public function beforeFilter() {
      //Configure AuthComponent
      $this-&gt;Auth-&gt;allow('display'); // Allows access to the homepage of the app
      $this-&gt;Auth-&gt;loginAction = array('controller' =&gt; 'users', 'action' =&gt; 'login');
      $this-&gt;Auth-&gt;logoutRedirect = array('controller' =&gt; 'users', 'action' =&gt; 'login');
      $this-&gt;Auth-&gt;loginRedirect = array('controller' =&gt; 'posts', 'action' =&gt; 'add');
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So as you can see the default is for users to be redirected on login to the posts controllers add() function, which works fine. However, how can I set a different login redirect for my admin_login() function?</p>
  
  <p>I've read a number of posts on here but most relate to older versions of cake and not cake 2.</p>
  
  <p>If it helps, this is my admin_login function in the UsersController.php</p>
  
  <pre><code>public function beforeFilter() {
      parent::beforeFilter();
      $this-&gt;Auth-&gt;allow('logout');
  }
  
  public function admin_login() {
      if ($this-&gt;request-&gt;is('post')) {
          if ($this-&gt;Auth-&gt;login()) {
              if ($this-&gt;Session-&gt;read('Auth.User')) {
                  $this-&gt;Session-&gt;setFlash('You are logged in!');
                  //$this-&gt;redirect($this-&gt;Auth-&gt;redirect());
  
                  // This doesnt work! Grrrrrr
                  //$this-&gt;redirect(array('controller'=&gt;'pages', 'action'=&gt;'admin_index'));
  
                  // This nearly works...
                  if($this-&gt;Auth-&gt;user())$this-&gt;redirect(array('controller' =&gt; 'pages', 'action' =&gt; 'admin_index'));
              }            
          }
          else {
              $this-&gt;Session-&gt;setFlash('Your username or password was incorrect.');
          }
      }
  </code></pre>
  
  <p>Could anyone point me in the right direction?</p>