在我看来,我有:
<?php
echo $this->Form->create('User', array("controller" => "Users", "action" => "login", "method" => "post"));
echo $this->Form->input('User.email', array("label" => false));
echo $this->Form->input('User.password', array("label" => false, 'class' => 'password-input'));
echo $this->Form->end(); ?>
在我的 AppController 中:
public $components = array(
'Session',
'Auth'
);
function beforeFilter(){
$this->Auth->fields = array(
'username' => 'email',
'password' => 'password'
);
}
在我的用户控制器中:
function beforeFilter(){
$this->Auth->allow('sign_up', 'login', 'logout', 'forgot_password');
return parent::beforeFilter();
}
public function login() {
if ($this->Auth->login()) {
$this->Session->setFlash(__('Successfully logged in'), 'default', array('class' => 'success'));
$this->redirect($this->Auth->redirect());
} else {
if (!empty($this->request->data)) {
$this->Session->setFlash(__('Username or password is incorrect'), 'default', array('class' => 'notice'));
}
}
}
但是登录不起作用,我错过了什么?
谢谢。