我有要求,我可以在新的添加功能中进行唯一值的验证
$this->form_validation->set_rules('email','Email','required|valid_email||is_unique[users.Email]');
Run Code Online (Sandbox Code Playgroud)
它的工作,但在编辑功能,它不工作..我有写回调函数来检查唯一的电子邮件.这是我在编辑功能中编写的代码
$this->form_validation->set_rules('email','Email','required|valid_email|callback_check_email');
function check_username($email)
{
$return_value = $this->user_model->check_email($email);
if ($return_value)
{
$this->form_validation->set_message('email_check', 'Sorry, This username is already used by another user please select another one');
return FALSE;
}
else
{
return TRUE;
}
}
Run Code Online (Sandbox Code Playgroud)
和user_model
function check_mail($email)
{
$sql = "SELECT users.Email
FROM users
WHERE
$email = users.Email
";
$result = $this->db->query($sql)->result_array();
return $result;
}
Run Code Online (Sandbox Code Playgroud)
我无法验证唯一的电子邮件