2012-08-10 92 views
0

我加入登錄/註銷能力,我的CakePHP的項目,當我登錄或註銷我收到以下錯誤:授權適配器"控制器)"找不到。在CakePHP中

錯誤: 授權適配器"控制器)"沒有被發現。 錯誤:發生內部錯誤。

堆棧跟蹤 CORE \蛋糕\控制器\元器件\ AuthComponent.php線376→AuthComponent-> constructAuthorize() CORE \蛋糕\控制器\元器件\ AuthComponent.php線路326→AuthComponent-> isAuthorized(數組) [內部函數]→AuthComponent->啓動(UsersController) CORE \ Cake \ Utility \ ObjectCollection.php第130行→call_user_func_array(數組,數組) [內部函數]→ObjectCollection->觸發器(CakeEvent) CORE \ Cake \ Event \ CakeEventManager.php第246行→call_user_func(array,CakeEvent) CORE \ Cake \ Controller \ Controller.php行671→CakeEventManager-> dispatch(CakeEvent) CORE \ Cake \ Routing \ Dispatcher.php第183行→Controller-> startupProcess() CORE \ Cake \ Routing \ Dispatcher.php第161行→Dispatcher - > _ invoke(UsersController,CakeRequest,CakeResponse) APP \ webroot \ index.php 92行→Dispatcher-> dispatch(CakeRequest ,CakeResponse)

這裏是我的AppController.php

class AppController extends Controller { 
    public $components = array(
     'Session', 
     'Auth'=>array(
      'loginRedirect'=> array('controller'=>'users', 'action'=>'index'), 
      'logoutRedirect'=> array('controller'=>'users', 'action'=>'index'), 
      'authError' =>"You can't access that page", 
      'authorize'=> array('Controller)') 
     ) 

    ); 
    //determines what logged in users have access to 
    public function isAuthorized($user){ 
     return true; 
    } 
    //determines what non-logged in users have access to 
    public function beforeFilter(){ 
     $this->Auth->allow('index','view'); 
     $this->set('logged_in', $this->Auth->loggedIn()); 
     $this->set('current_user', $this->Auth->user()); 
    } 


} 

這裏是我的UsersController.php

class UsersController extends AppController { 
    public $name = 'Users'; 

    public function beforeFilter(){ 
     parent::beforeFilter(); 
     $this->Auth->allow('add'); 
    } 

    public function login(){ 
     if($this->request->is('post')){ 
      if($this->Auth->login()){ 
       $this->redirect($this->Auth->redirect()); 

      }else{ 
       $this->Session->setFlash('Your username and/or password is incorrect'); 
      } 
     } 
    } 

    public function logout(){ 
     $this->redirect($this->Auth->logoutRedirect()); 
    } 

我注意到一對夫婦與他們同樣的錯誤類似的職位,但涉及的問題是AA麗努x機器,我在窗口,或調用一個函數,我不打電話。

回答

4

你在你的$components['Auth']數組中犯了一個錯誤。你寫了'Controller)'而不是'Controller'(錯誤消息告訴你)。這裏的修正$components

public $components = array(
    'Session', 
    'Auth'=>array(
     'loginRedirect'=> array('controller'=>'users', 'action'=>'index'), 
     'logoutRedirect'=> array('controller'=>'users', 'action'=>'index'), 
     'authError' => "You can't access that page", 
     'authorize'=> array('Controller') 
    ) 

); 
+0

我的錯誤,感謝指出這一點 – 2012-08-10 18:53:25

+0

,不要忘記你的蛋糕2.x的情況下,你必須完全一樣的情況下。這是我的錯誤,這個答案幫助我。呵呵呵... – Kenjiro 2012-08-24 05:36:45