Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将自定义错误消息添加到CI验证_errors()_Php_Codeigniter - Fatal编程技术网

Php 将自定义错误消息添加到CI验证_errors()

Php 将自定义错误消息添加到CI验证_errors(),php,codeigniter,Php,Codeigniter,有一种方法可以将自定义错误消息添加到CodeIgnitervalidation_errors() 例如,如果我想要一个带有123456值的字段,并且用户输入12345,我希望设置一条消息,说明: 数字6是必需的 以及我想添加的任何其他自定义规则。像一个特定的模式或任何其他东西 对不起,我的英语不好。是的,那是可能的 使用回调函数设置规则,如 $this->form_validation->set_rules('field_name', 'Number', 'callback_cust

有一种方法可以将自定义错误消息添加到CodeIgniter
validation_errors()

例如,如果我想要一个带有
123456
值的字段,并且用户输入
12345
,我希望设置一条消息,说明:

数字6是必需的

以及我想添加的任何其他自定义规则。像一个特定的模式或任何其他东西

对不起,我的英语不好。

是的,那是可能的

使用回调函数设置规则,如

$this->form_validation->set_rules('field_name', 'Number', 'callback_custom_validation');
并在同一控制器中定义回调,如

public function custom_validation($str)
{
    if ($str != '123456')
    {
        $this->form_validation->set_message('field_name', 'The %s field requires 123456');
        return false;
    }
    else
    {
        return true;
    }
}
使用


有关回调的更多信息。

我认为set_message()的第一个参数应该是回调函数的名称$此->表单\u验证->设置\u消息('自定义\u验证',%s字段需要123456');