我有一个修改过的AppController.php,logins_controller.php和一些视图
对于已知用户,我收到以下错误消息:不确定原因,因为我指向正确的控制器...有什么建议吗?
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>
答案 0 :(得分:1)
所以看来问题是使用控制器授权。
所以我刚刚删除了这一行:
$this->Auth->authorize = 'controller';
我认为它使用基本身份验证。
答案 1 :(得分:1)
CakePHP尝试根据参数查找类文件。例如,'controller'意味着它试图找到controllerAuthorize.php。它在Windows上找到它,因为文件不区分大小写。
在Unix / Linux系统上,您应该使用标题大小写:
'authorize' => array('Controller')
答案 2 :(得分:1)
尝试 App :: uses('AppController','Controller');
登录控制器中的
也 $ this-&gt; Auth-&gt; authorize ='controller';
应该是 $ this-&gt; Auth-&gt; authorize = array('Controller');
(虽然我从蛋糕2.0的角度谈论)