我正在检查我的数据库中已经存在的国家/地区名称我使用了回调,但它没有发出任何错误
$this->form_validation->set_rules('country_name', 'Country Name',
'trim|required|xss_clean|callback_check_exist');
这是我的控制器功能
function check_exist($country_name)
{
$this->countrymodel->country_exists($country_name);
}
这是我的模型
function country_exists($key)
{
$this->db->where('country_name',$key);
$this->db->from($this->dbname);
$query = $this->db->get();
if ($query->num_rows()> 0){
return true;
}
else{
return false;
}
}