Javascript 在cakephp中添加新用户
我是用户Cakephp 2.3.8 我在注册新用户时遇到问题,我在Javascript 在cakephp中添加新用户,javascript,ajax,cakephp,Javascript,Ajax,Cakephp,我是用户Cakephp 2.3.8 我在注册新用户时遇到问题,我在userscocontroller.php中的函数是 function registration() { if (!empty($this->request->data)) { if ($this->request->data['User']['password'] === $this->request->data['User']['confirmPass
userscocontroller.php
中的函数是
function registration() {
if (!empty($this->request->data)) {
if ($this->request->data['User']['password'] === $this->request->data['User']['confirmPassword']) {
// echo "dfgf"; die;
$this->request->data['User']['status'] = 1;
$myPassword = $this->request->data['User']['password'];
$this->request->data['User']['password'] = Security::hash($myPassword, null, true);
$repassword = $this->request->data['User']['confirmPassword'];
$this->request->data['User']['confirmPassword'] = Security::hash($repassword, null, true);
} else {
}
if ($this->User->save($this->request->data)) {
$this->redirect('/');
} else {
}
}
}
当我保存此值而不保存在表中时,我的模型为
class User extends AppModel {
public $validate = array(
'username' => array(
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'required' => true,
'message' => 'Alphabets and numbers only'
),
'isUnique' => array(
'rule' => 'isUnique',
'on' => 'create', // here
'last' => false,
'message' => 'user name allready exist please choose another one'
)
),
'emailId' => array(
'email' => array(
'rule' => 'email',
'required' => true,
'message' => 'please enter an valid email'
),
'isUnique' => array(
'rule' => 'isUnique',
'on' => 'create', // here
'last' => false,
'message' => 'email allready exist please choose another one'
)
),
'password' => array(
'match' => array(
'rule' => array('match', 'confirmPassword'),
'message' => 'Passwords doesnt match',
),
),
);
/**
* match for form validation
*
* @
* @return ture or flase
*/
public function match($check, $with) {
// Getting the keys of the parent field
foreach ($check as $k => $v) {
$$k = $v;
}
// Removing blank fields
$check = trim($$k);
$with = trim($this->data[$this->name][$with]);
// If both arent empty we compare and return true or false
if (!empty($check) && !empty($with)) {
return $check == $with;
}
// Return false, some fields is empty
return false;
}
}
您遇到了什么问题?请删除密码验证,然后重试。尝试添加调试行($this->User->validationErrors);就在你试图拯救之后。这将告诉你什么是无法验证的。谢谢@anil Kumar现在它工作正常(在删除密码验证后)