This question already has an answer here:
- CakePHP undefined index error 2 answers
I'm using CakePHP 2.3 and here's my AppController.php
and UsersController.php
files, pieces that are relevant to user log in:
class AppController extends Controller {
public $helpers = array('Html', 'Form', 'Session');
public $components = array(
'RequestHandler',
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'dpts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
)
);
public function beforeFilter() {
$this->UserAuth->beforeFilter($this); // Error fires here.
$authUser = $this->UserAuth->getUser();
$this->set('loggedInUser', $authUser);
}
}
=================================================================================
<?php
class UsersController extends AppController {
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect(array('action' => 'index', 'controller' => 'pages'));
} else {
$this->Session->setFlash(__('Correo y/o contraseña incorrecta.'));
}
}
}
}
How can I get the object of the user currently logged in?
I'm getting an error in the beforeFilter() of the AppController:
Fatal error: Call to a member function beforeFilter() on a non-object in C:\xampp\htdocs\testapp\app\Controller\AppController.php on line 50
</div>