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 { }
UsersController
<?php App::uses('ProtectedController', 'Controller'); class UsersController extends ProtectedController { public function beforeFilter() { parent::beforeFilter(); $this->Auth->allow('add', 'logout'); } }
I had
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
.
Is there anyone how to solve this. From what I see, it should load the component in the ProtectedController, and AuthComponent will be loaded.
EDIT:
line 18 is the ProtectedController:
public function beforeFilter() { $this->Auth->allow('index', 'view'); }
EDIT:
You can fix this only now:
public $components = array( 'Session', 'Auth' => array( 'loginRedirect' => array('controller' => 'home', 'action' => 'index'), 'logoutRedirect' => array('controller' => 'home', 'action' => 'index') ) );
in AppController then override and then allow everyone:
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('*'); } }