-1

我正在检查我的数据库中已经存在的国家/地区名称我使用了回调,但它没有发出任何错误

$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;
            }
        }
4

1 回答 1

0

回调函数应该返回一个值并设置一条消息:

function check_exist($country_name)
{
     if (!$this->countrymodel->country_exists($country_name)) {
         $this->form_validation->set_message('check_exist', 'an error message');
         return FALSE;
     }
     else {
         return TRUE;
     }
}
于 2012-08-02T09:40:30.943 回答