2014-10-29 53 views
1

在這裏我的控制器名稱是AucUsersController。使用auth組件後,它找到userscontroller.I想要更改此目錄。我已經嘗試了以下代碼,但它不起作用。如何更改cakephp auth組件控制器?

public $components = array('Paginator'=>array('limit'=>2),'Auth'=>array(
      'Controller'=>'AucUsers', 
      'loginRedirect' => array('controller' => 'aucusers','action' => 'index'), 
      'logoutRedirect' => array('controller' => 'aucusers','action' => 'index'), 
      'authError'=>'You can not access this page!!', 
)); 

如何更改此默認控制器?

+0

您是否從文檔閱讀本http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#creating-custom-authorize -objects;您不創建控制器。您創建AppController的一個驗證組件 – gmponos 2014-10-29 09:57:59

+0

後添加AUTH組件,默認情況下搜索在userscontroller.But登錄動作在這裏我使用AucUsersController,所以沒有任何UsersController.After在AppController中添加驗證組件現在它的搜索一個userscontroller.But我沒有任何用戶控制器。 – 2014-10-29 10:02:45

+0

對不起。我以爲你想製作自己的認證組件。 – gmponos 2014-10-29 10:18:14

回答

3

CakePHP的默認情況下使用的用戶/登錄在loginAction, 則loginAction是你定義控制器和動作,其中蛋糕確實登錄

public $components = array('Paginator'=>array('limit'=>2),'Auth'=>array(
      'loginAction' => array(
      'controller' => 'aucusers', 
      'action' => 'login' 
     ), 
      'loginRedirect' => array('controller' => 'aucusers','action' => 'index'), 
      'logoutRedirect' => array('controller' => 'aucusers','action' => 'index'), 
      'authError'=>'You can not access this page!!', 
)); 

loginRedirect屬性 - 它表示其中用戶應登錄 後重定向到logoutRedirect - 它代表其中用戶應該重定向到註銷後

0

我相信如果你想改變默認控制器,你必須設置UserModel選項。我將它設置爲beforeFilter方法。所以在你的情況下,它會。

/** 
* beforeFilter method 
* 
* @return void 
*/ 
public function beforeFilter() { 
    $this->Auth->authenticate = array(
     'Form' => array(
      'userModel' => 'AucUser', 
     ) 
    ); 

    return parent::beforeFilter();  
} 

我在文檔中沒有看到有任何控制器選項。

+0

我試過這段代碼,它不工作。 – 2014-10-29 10:31:49

+0

你能定義它不工作嗎? – gmponos 2014-10-29 10:34:36