受保护的控制器.php
<?php
class ProtectedController extends AppController {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'home', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'home', 'action' => 'index')
)
);
public $paginate = array(
'limit' => 2
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
}
应用控制器
App::uses('Controller', 'Controller');
class AppController extends Controller {
}
用户控制器
<?php
App::uses('ProtectedController', 'Controller');
class UsersController extends ProtectedController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add', 'logout');
}
}
我一直在
Fatal Error
Error: Call to a member function allow() on a non-object
File: /Library/WebServer/Documents/cakephp_stats/app/Controller/ProtectedController.php
Line: 18
Notice: If you want to customize this error message, create app/View/Errors/fatal_error.ctp
现在的错误。
有人如何解决这个问题。从我所看到的情况来看,它应该在 ProtectedController 中加载组件,并且 AuthComponent 将被加载。
编辑:
第 18 行是 ProtectedController:
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
编辑:
我现在唯一能做的就是剪掉这个:
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'home', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'home', 'action' => 'index')
)
);
到 AppController 然后覆盖然后允许那里的每个人:
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'home', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'home', 'action' => 'index')
)
);
public function beforeFilter() {
$this->Auth->allow('*');
}
}