【发布时间】:2014-10-30 04:52:35
【问题描述】:
添加用户时出现此错误。
我有一个视图 adduser.ctp
在用户控制器中我有这个功能
public function addUser() {
$userGroups = $this->UserGroup->getGroups();
unset($userGroups[1]);
unset($userGroups[2]);
$this->set('userGroups', $userGroups);
if ($this->request->isPost()) {
$this->User->set($this->data);
if ($this->User->AddEditValidate()) {
$this->request->data['User']['email_verified'] = 1;
$this->request->data['User']['active'] = 2;
$this->request->data['User']['parent_id'] = $this->Session->read('logged_client_id');
$salt = $this->UserAuth->makeSalt();
$this->request->data['User']['salt'] = $salt;
$this->request->data['User']['temp_password'] = $this->request->data['User']['password'];
$this->request->data['User']['password'] = $this->UserAuth->makePassword($this->request->data['User']['password'], $salt);
if ($this->User->save($this->request->data, false)) {
$this->sendLoginEmail($this->request->data['User']);
$this->Session->setFlash(__('The user is successfully added'), 'success_flash');
$this->redirect('/clientUsers/' . $this->Session->read('logged_client_id'));
} else {
$this->Session->setFlash(__('Problem in saving user information'), 'error_flash');
}
}
}
}
现在在用户模型中,我通过以下函数验证
function AddEditValidate() {
$validate1 = array(
"user_group_id" => array(
'rule' => array('comparison', '!=', 0),
'message' => 'Please select group'),
'first_name' => array(
'mustNotEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Please enter first name'),
'custom' => array(
'rule' => 'alphaNumericSpace',
'message' => 'First name should be alphnumeric')
),
'last_name' => array(
'mustNotEmpty' => array(
'rule' => 'notEmpty',
'on' => 'create',
'message' => 'Please enter last name'),
'custom' => array(
'rule' => 'alphaNumericSpace',
'message' => 'Last name should be alphnumeric')
),
'email' => array(
'mustNotEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Please enter email',
'last' => true),
'mustBeEmail' => array(
'rule' => array('email'),
'message' => 'Please enter valid email',
'last' => true),
'mustUnique' => array(
'rule' => 'isEmailUnique',
'message' => 'This email is already registered',
)
),
'oldpassword' => array(
'mustNotEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Please enter old password',
'last' => true),
'mustMatch' => array(
'rule' => array('verifyOldPass'),
'message' => 'Please enter correct old password'),
),
'password' => array(
'mustNotEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Please enter password',
'on' => 'create',
'last' => true),
'complex' => array(
'rule' => array('complexPassword'),
'message' => 'Password should be six characters long, which should have minimum one alphabet, one number and one special character',
),
),
'captcha' => array(
'mustMatch' => array(
'rule' => array('recaptchaValidate'),
'message' => ''),
)
);
$this->validate = $validate1;
return $this->validates();
}
它给了我错误
错误:SQLSTATE[42000]:语法错误或访问冲突:1064 你 您的 SQL 语法有错误;检查对应的手册 您的 MySQL 服务器版本,以便在附近使用正确的语法 第 1 行的“AddEditValidate”
SQL 查询:AddEditValidate
请帮帮我。
谢谢
【问题讨论】:
-
我知道这个问题被问了很多次,但它不能解决我的问题。在用户控制器中,功能是 if ($this->User->AddEditValidate()) {} 即使我尝试 if ($this->User->AddEditValidatee()) {} 但它给了我同样的错误。在我输入 AddEditValidatee 的问题中,这是错误的。我知道它应该是 AddEditValidate。
-
检查拼写使用 AddEditValidate 而不是 AddEditValidatee
-
使用 $this->request->data 而不是 $this->data ,编辑您的问题以便更好地理解,以便其他人可以提供帮助
-
@Abhishek $this->request->data 没有解决我的问题,我编辑了问题。
-
将函数设为public并设为小写:
public function addEditValidate