Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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 无法访问与字段名对应的错误消息_Php_Codeigniter - Fatal编程技术网

Php 无法访问与字段名对应的错误消息

Php 无法访问与字段名对应的错误消息,php,codeigniter,Php,Codeigniter,我有一个检查captcha的回调函数,它查看$row是==0还是==1(此信息从sql查询) 问题是我不能从$self->form\u validation->set\u rule('captcha','call\u back\u check\u captcha')调用它,因为我的函数接受了一个$row变量。我现在调用它的方式得到了一条无法访问的错误消息。我怎样才能做到这一点 function check_captcha( $row) { if($row ==0)//didnt find

我有一个检查captcha的回调函数,它查看
$row
==0
还是
==1
(此信息从sql查询)

问题是我不能从
$self->form\u validation->set\u rule('captcha','call\u back\u check\u captcha')
调用它,因为我的函数接受了一个
$row
变量。我现在调用它的方式得到了一条无法访问的错误消息。我怎样才能做到这一点

function check_captcha( $row)
{
    if($row ==0)//didnt find any
    {
        $this->form_validation->set_message('captcha', 'text dont match captcha');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}


function create_member() 
        {   

            $past = time() - 7200; 

        $this->db->query("DELETE FROM captcha WHERE captcha_time <".$past);                 
        $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word =? AND ip_address =?";     
        $binds = array($_POST['captcha'], $this->input->ip_address(), $past);
        $query= $this->db->query($sql, $binds);

        $row = $query->row(); //row query rows : if it found an entry =1 

            $self->check_captcha($row->count);

        //VALIDATIONS
        $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');      
        $this->form_validation->set_rules( 'email_address', 'Email Address', 'trim|required|valid_email|unique[user.email_address]');
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|unique[user.username]');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_leng[32]');
        $this->form_validation->set_rules('password2', 'Password Confirmation','trim|required|matches[password]');
        if(!$_POST['captcha']){
        $this->form_validation->set_rules('captcha', 'Captcha','trim|required');}else{
        $this->form_validation->set_rules('captcha', 'Captcha', 'callback_check_captcha');}

        if($this->form_validation->run()==FALSE)
        {   //this -> to the curr obj(UserController) && registraion() points to the the function in controller
            $this->registration();  //reloads reg page so they can fill out right stuff
        }
        else
功能检查\u验证码($row)
{
if($row==0)//未找到任何
{
$this->form_validation->set_message('captcha','text not match captcha');
返回FALSE;
}
其他的
{
返回TRUE;
}
}
函数create_member()
{   
$pass=time()-7200;
$this->db->query(“从验证码中删除,其中验证码时间

消息名称对应于函数,而不是字段。因此,将其设置为“检查验证码”将修复您的错误。错误消息将使用正确的字段名称。

实际上,最好的方法不是直接在控制器上写入错误消息,而是添加此条目“检查验证码”“关于语言

在我的例子中,验证规则(表单验证)“小于”的消息不存在

我更改了文件/system/language/?/form\u validation\u lang.php。我添加了缺少的条目。

这对我很有帮助

转到application/config/autoload.php并在那里添加“Security”助手类

$autoload['helper'] = array('security');
或者在表单验证之前添加此项

$this->load->helper('security');

在语言文件中添加一个条目,其中包含错误消息(yourfieldname)中部分的名称-这解决了问题

您可以在
设置规则中设置错误消息

$this->form\u validation->set\u rules('captcha','captcha','callback\u check\u captcha',


array('check_captcha'=>'text not match captcha');

是的。我还通过添加缺少的语言文本修复了此消息。是否同样的错误让我困惑,您在这里使用的是
set_message()
,但问题发起者使用的是
set_rules()
。这是您的打字错误吗?顺便说一句,我也使用了
set_rules()
和具有相同的消息。我使用了函数名而不是字段名,但它仍然显示相同的错误消息。我已经有一个单独的语言文件包含错误消息,因此我不希望在表单\u validation\u lang文件中添加更多行,以避免将来出现差异。我现在该怎么办?您应该添加一个
\u
在函数名前面,这样就不能从url调用我。
check\u captcha
应该是
\u check\u captcha
$this->load->helper('security');