Cakephp isUnique无法正常工作 [英] Cakephp isUnique is not working properly
问题描述
isUnique验证将不起作用。
模型代码为:
isUnique validation doesn't work if there there is validation error only of uniqueness in user creating form and gives error of 'The page isn't redirecting properly'. Model code is:
class User extends AppModel {
public $validate = array(
'username' => array(
'notEmpty' => array(
'rule' => array('email'),
'message' => 'Please supply a valid email address.'
),
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'This email has already been taken.'
)
),
'password' => array(
'min' => array(
'rule' => array('minLength', 3),
'message' => 'Password must be at least 3 characters.'
),
'required' => array(
'rule' => 'notEmpty',
'message' => 'Please enter a password.'
),
),
'cpassword' => array(
'required' => 'notEmpty',
'match' => array(
'rule' => 'validatePasswdConfirm',
'message' => 'Passwords do not match'
)
)
);
}
当我输入不匹配的密码时,会提示密码不匹配如果用户名已存在于用户表中,但问题是当我仅输入已经存在的用户名并输入匹配密码,然后出现错误 The页面未正确重定向。
如何解决此问题?
预先感谢。
When I enter mismatch passwords then it gives error of 'Passwords do not match' and also gives error 'This email has already been taken.' if a username is already there in users table but the problem is when I Only enter the username which already exists and enter a match password then it goes to a page with error "The page isn't redirecting properly". How can I fix this issue? Thanks in advance.
推荐答案
(如果您已使用 $ this-> Auth-> login()
在beforeFilter中是否有任何条件,请将其删除,然后使用!empty($ this-> Auth-> user('id'))
代替 $ this-> Auth-> login()
为您在beforeFilter中的条件。
if you have used $this->Auth->login()
in beforeFilter for any condition, remove it and use !empty($this->Auth->user('id'))
instead of $this->Auth->login()
for you conditions in beforeFilter.
这篇关于Cakephp isUnique无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!