ProtectedController.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');
}
}
AppController
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('*');
}
}