我正在努力确保不同用户的团队名称不同。所有用户都应具有唯一的团队名称,但代码不能正常工作。我试着设置验证,但它似乎不起作用。我正在使用代码点火器平台
<?php
class Profile_model extends CI_Model{
function __construct()
{
parent::__construct();
}
public function update($postData, $id) {
$dateOfBirth = str_replace('/', '-', $postData['dateOfBirth']);
$updateData = array(
'name' => $postData['name'],
'teamName' => $postData['teamName'],
'dateOfBirth' => !empty($postData['dateOfBirth']) ? date('Y-m-d', strtotime($dateOfBirth)) : NULL,
'gender' => $postData['gender'],
'email' => $postData['email'],
'mobile' => $postData['mobile'],
'address' => $postData['address'],
'city' => $postData['city'],
'state' => $postData['state'],
'country' => $postData['country'],
'pinCode' => $postData['pinCode'],
'updatedAt' => date('Y-m-d H:i:s')
);
$this->db->where('id', $id);
$this->db->update('customer', $updateData);
$this->db->update('customer', 'teamName', 'required|is_unique[teamName]');
$returnData = array(
'success' => 1
);
return $returnData;
}
public function exists_in_database($teamName)
{
$query = $this->db->get_where('customer', array('teamName' => $teamName));
if ($query->num_rows() == 0 )
{
$this->form_validation->set_message('exists_in_database', 'Please enter an new teamName');
return FALSE;
}
else
{
return TRUE;
}
}
}*
答案 0 :(得分:0)
你可能在代码中做错了