我试着登录用户时收到以下错误致命错误:上将auth登录
Call to a member function login() on a non-object
我的登录操作使用外部模型。的动作是:被传递给$this->Auth->login
public function login() {
$this->loadModel('User');
if ($this->request->is('post')) {
$theUser = $this->User->find('first', array('conditions' => array('User.username' => $this->request->data['User']['username'])));
if($theUser['User']['activated'] == TRUE){
if ($this->Auth->login($this->request->data)){
$this->Session->setFlash('Logged in successfully');
$this->redirect(array('controller' => 'admin', 'action' => 'index'));
} else {
$this->Session->setFlash('Username or password is incorrect');
}
}else $this->Session->setFlash('User not yet activated. Please Contact administrator.');
}
}
请求数据是:
array(
'User' => array(
'password' => '*****',
'username' => 'admin'
)
)
$this->Auth->login($this->request->data)
是造成致命错误的行。
有人可以请解释什么是错误意味着什么,并可能导致它?
它在第二行上面列出: '调用成员函数登录()在非对象' – BIOS 2013-03-15 19:51:50
你有没有包含Auth组件? – 2013-03-15 19:53:45
刚刚注意到,为什么你明确加载你的用户模型? – 2013-03-15 19:56:26