Php CodeIgniter num_rows()不工作?
好吧,我不知道什么不起作用。我知道我的表单验证确实有效,因为我的所有其他函数都能正常工作,但我正在设置消息,不管消息是真是假,并且没有任何消息显示出来,所以我觉得它跳过了验证规则。。这很奇怪Php CodeIgniter num_rows()不工作?,php,codeigniter,Php,Codeigniter,好吧,我不知道什么不起作用。我知道我的表单验证确实有效,因为我的所有其他函数都能正常工作,但我正在设置消息,不管消息是真是假,并且没有任何消息显示出来,所以我觉得它跳过了验证规则。。这很奇怪 $this->form_validation->set_rules('region', 'required|valid_region'); MY libraries文件夹中MY_Form_validation.php中的规则。首先加载库。正如我所说的,我的所有其他验证都能正常工作,比如我的re
$this->form_validation->set_rules('region', 'required|valid_region');
MY libraries文件夹中MY_Form_validation.php中的规则。首先加载库。正如我所说的,我的所有其他验证都能正常工作,比如我的reCaptcha和所有东西
function valid_region($str) {
$this->load->database();
if($this->db->query('SELECT id
FROM region
WHERE name = ?
LIMIT 1', array($str))->num_rows() == 0) {
//not a valid region name
$this->set_message('valid_region', 'The %s field does not have a valid value!');
return false;
}
$this->set_message('valid_region', 'Why is it validating?');
}
没有一条消息会被设置,所以我感觉没有任何东西在验证 而不是
$this->form_validation->set_rules('region', 'required|valid_region');
$this->set_message
试一试
使用自定义验证规则时,应使用
回调以在函数名前加前缀
更新
和使用
$this->form_validation->set_message
而不是
$this->form_validation->set_rules('region', 'required|valid_region');
$this->set_message
并且在功能有效\u区域
验证成功时使用返回真值
而不是
$this->form_validation->set_rules('region', 'required|valid_region');
$this->set_message
试一试
使用自定义验证规则时,应使用
回调以在函数名前加前缀
更新
和使用
$this->form_validation->set_message
而不是
$this->form_validation->set_rules('region', 'required|valid_region');
$this->set_message
并且在功能有效\u区域
验证成功时使用返回true
函数接受3个参数
$this->form_validation->set_rules('region', 'Region', 'required|valid_region');
函数包含3个参数
$this->form_validation->set_rules('region', 'Region', 'required|valid_region');
@Peant正在扩展核心验证类,验证函数已在扩展类
MY\u Form\u validation
中声明。因此,他不必在函数名前面加上回调
@peant正在扩展核心验证类,并且验证函数已在扩展类我的表单验证
中声明。因此,他不必在函数名前面加上callback\uuu