您可以使用應用程序中任何控制器內的Auth組件。如果你想它只會影響到管理部分,那麼你可以在你的應用程序AppController的Auth初始化中的beforeFilter函數中添加條件。
// for component initialization.
public $components = array(
'Auth' => array(
'authenticate' => array(
'userModel' => 'Customer', // you can also specify the differnt model instead of user
'Form' => array(
'fields' => array('username' => 'email')
)
)
)
}
,您可以如果您使用的蛋糕2.3.x版本或更高版本,那麼要確保已經指定像正確的格式重定向操作上管理路由綁定這個喜歡
function beforeFilter(){
// only works with admin routing.
if(isset($this->request->params['prefix']) && ($this->request->params['prefix'] == 'admin')){
$this->Auth->loginRedirect = array('admin' => true, 'controller' => 'pages', 'action' => 'index');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => true);
$this->Auth->loginAction = array('admin' => true, 'controller' => 'customers', 'action' => 'login');
}
}
。
return $this->redirect('action_name'); // you can also specify the array of parameters.
類似的問題:http://stackoverflow.com/questions/16820195/cakephp-admin-section-routing-and-redirecting – Dezigo