我正在使用 CakePHP 2.3,这是我的AppController.php
和UsersController.php
文件,与用户登录相关的部分:
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.'));
}
}
}
}
如何获取当前登录用户的对象?
我在 AppController 的 beforeFilter() 中遇到错误:
致命错误:在第 50 行的 C:\xampp\htdocs\testapp\app\Controller\AppController.php 中的非对象上调用成员函数 beforeFilter()