2013-07-28 89 views
0
public function login() { 
     if ($this->request->is('post')) { 
      if ($this->Auth->login()) { 
       $this->redirect($this->Auth->redirect()); 
      } else { 
       $this->Session->setFlash(__('Invalid username or password, try again')); 
      } 
     } 
    } 

這是我的登錄腳本和登錄CakePHP中沒有重定向

public $components = array('Acl', 'Session', 
     'Auth' => array('authorize' => array('Controller'), 
         'loginRedirect' => array('controller' => 'users', 'action' => 'dashboard'), 
         'logoutRedirect' => array('controller' => 'users', 'action' => 'login'), 
         'authenticate' => array('Form' => array('fields' => array('username' => 'email'))) 

     ) 
    ); 

這是權威性compnents appcontroller.php

它登錄使用電子郵件和密碼,但它不是重定向到用戶/儀表板

但是,而不是如果我把任何外部URL它完全重定向

eg: 'loginRedirect' => 'http://google.com', 

它重定向至Google,

我完全lost.kindly幫助

+0

如果您最有可能檢查您重定向到loginRedirect,然後立即重定向回登錄屏幕(爲什麼,是爲了找出 - 這是某種應用程序錯誤)。 – AD7six

+0

@ AD7six:下面的答案固定它。感謝您的寶貴時間 – zamil

回答

1

確保你被允許查看使用儀表板頁面:AuthComponent::allow()

添加這個方法來你的控制器:

public function beforeFilter() { 
    $this->Auth->allow('dashboard'); 
} 

確保有爲儀表板頁面設置的路線

+0

我應該在哪裏給點一個代碼?爲什麼我應該爲此設置一個路由。我有我的用戶控制器 – zamil

+0

公共功能儀表板(){}我認爲你應該使用:'$ this-> Auth-> allow('dashboard');'允許儀表板操作。我將代碼添加到我的答案中。 –

+0

謝謝你的工作 – zamil