4
ProtectedController.phpCakePHP的:調用一個成員函數允許()
<?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');
}
}
AppController的
App::uses('Controller', 'Controller');
class AppController extends Controller {
}
UsersController
<?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('*');
}
}
您將需要在UserController中添加$組件 –
@MoyedAnsari我似乎並不需要它在UserController中。 –
確實增加了函數__construct(){parent :: __ construct(); }在你的受保護的控制器中修復它? – Steve