我已经检查了cakephp验证了很长时间来验证我的登录表单。我的问题是当我输入用户名和密码作为空白验证没有显示。在UserController.phpcakephp登录表单验证的空白用户名和密码
登录功能包含
if ($this->request->is('post')) {
$this->user->set($this->request->data);
$errors = $this->user->invalidFields();
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash($this->Auth->authError, 'default', array(), 'auth');
$this->redirect($this->Auth->loginAction);
}
} else {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
}
我user.php的模型包含验证为
public $validate = array(
'username' => array(
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'The username has already been taken.',
),
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank.',
),
),
'email' => array(
'email' => array(
'rule' => 'email',
'message' => 'Please provide a valid email address.',
),
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'Email address already in use.',
),
),
'password' => array(
'rule' => array('minLength', 6),
'message' => 'Passwords must be at least 6 characters long.',
),
'current_password' => array(
'rule' => '_identical',
),
'name' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank.',
),
);
其实我的登录表单只包含usgername和密码。但我已经为用户注册表单设置了此验证。验证以注册形式正确工作,但在登录时验证不起作用。是的,我知道在这个网站上发布了很多关于同一问题的问题,但没有解决我的问题,我尝试了所有的stackoverflow问题。
$this->Model->validates();
你没有得到验证错误,因为你没有实际验证您的数据:请帮助
验证用户详细信息没有意义,可以登录或不登录。 – dogmatic69