我是用户 Cakephp 2.3.8 我在注册新用户时遇到问题,我的功能Userscontroller.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;
}
}