2012-01-06 80 views
0

我有一個修改AppController.php,logins_controller.php,以及一些看法CakePHP的身份驗證組件給控制器沒有找到消息

對於knownusers的我收到以下錯誤信息:不知道爲什麼,因爲我指着正確的控制器......任何建議?

http://my.ip.address/cakephp/logins/knownusers

Authorization adapter "controller" was not found. 

Error: An Internal Error Has Occurred. 
Stack Trace 

#0 /var/www/cakephp/lib/Cake/Controller/Component/AuthComponent.php(376): AuthComponent->constructAuthorize() 
#1 /var/www/cakephp/lib/Cake/Controller/Component/AuthComponent.php(330): AuthComponent->isAuthorized(Array) 
#2 [internal function]: AuthComponent->startup(Object(LoginsController)) 
#3 /var/www/cakephp/lib/Cake/Utility/ObjectCollection.php(103): call_user_func_array(Array, Array) 
#4 /var/www/cakephp/lib/Cake/Controller/Controller.php(606): ObjectCollection->trigger('startup', Array) 
#5 /var/www/cakephp/lib/Cake/Routing/Dispatcher.php(104): Controller->startupProcess() 
#6 /var/www/cakephp/lib/Cake/Routing/Dispatcher.php(89): Dispatcher->_invoke(Object(LoginsController), Object(CakeRequest), Object(CakeResponse)) 
#7 /var/www/cakephp/app/webroot/index.php(96): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse)) 
#8 {main} 

AppController.php

App::uses('Controller', 'Controller'); 

/** 
* This is a placeholder class. 
* Create the same file in app/Controller/AppController.php 
* 
* Add your application-wide methods in the class below, your controllers 
* will inherit them. 
* 
* @package  Cake.Controller 
* @link http://book.cakephp.org/view/957/The-App-Controller 
*/ 
class AppController extends Controller { 

public $components = array('Auth'); 

public $helpers = array('Session', 'Html', 'Form', 'Session'); 

function beforeFilter(){ 
     $this->Auth->loginAction = array('controller' => 'logins', 'action' => 'login'); 
     $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'home'); 
     $this->Auth->allow('display'); 
     $this->Auth->authorize = 'controller'; 
     $this->set('Auth',$this->Auth); 
} 

     function isAuthorized() { 
       return true; 
     } 

} 

logins_controller.php

<?php 
class LoginsController extends AppController { 

     public $name = 'Logins'; 

     function beforeFilter() { 
       // tell Auth not to check authentication when doing the 'register' action 
       parent::beforeFilter(); 
       //$this->Auth->allow('register'); 
     } 

     function register() { 
       if (!empty($this->data)){ 
         if ($this->Login->save($this->params['data'])) { 
           // $this->flash('Your registration information was accepted. Welcome!','/pages/display/home'); 
           $this->Auth->login($this->data); 
           $this->redirect('/pages/display/home'); 
         } else { 
           $this->flash('There was a problem with your registration', '/logins/register'); 
         } 
       }  

     } 

function login() { 
       if(!empty($this->data)) { 
         $this->Auth->login($this->data); 
         $this->redirect('/pages/display/home'); 
       } 
     } 

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

} 
?> 

login.ctp

<h1>User Login Form</h1> 

<?php 
echo $this->Form->create('Login', array('action'=>'login')); 
echo $this->Form->input('username'); 
echo $this->Form->input('password', array('type'=>'password')); 
echo $this->Form->submit(); 
echo $this->Form->end(); 
?> 

knownusers.ctp

<table> 
<?php 
echo $this->Html->tableHeaders(array_keys($knownusers[0]['Login'])); 

foreach ($knownusers as $thisuser) 
{ 
     echo $this->Html->tableCells($thisuser['Login']); 
} 

?> 
</table> 

回答

1

CakePHP嘗試根據參數找到類文件。例如'controller'意味着它試圖找到controllerAuthorize.php。它在Windows上找到它,因爲文件不區分大小寫。

在Unix/Linux系統,你應該使用標題大寫:

'authorize' => array('Controller') 
1

這樣看來,這個問題是使用控制器權限。

所以我就刪除了這條線:

$this->Auth->authorize = 'controller'; 

我相信使得它使用基本身份驗證。

1

嘗試 應用::使用( 'AppController的', '控制');

在登錄控制器

也 $這 - > Auth->授權= '控制器'

;

應該是 $ this-> Auth-> authorize = array('Controller');

(雖然我是從蛋糕2.0的角度講的)