Codeigniter 3表单验证回调不起作用

AL *_* DI 2 php codeigniter

我在我的codeigniter验证中有一个自定义回调没有被调用,我只是无法弄清楚错误在哪里.

这是我的控制器:

$this->form_validation->set_error_delimiters('', '');
$this->form_validation->set_rules('pedido', 'numero de pedido', 'trim|required|integer');
$this->form_validation->set_rules('cliente', 'nombre del cliente', 'trim|required|alpha_numeric_spaces');
$this->form_validation->set_rules('motivo', 'motivo de la devolucion', 'trim|required|alpha_numeric_spaces');
$this->form_validation->set_rules('imagen', 'imagen', 'callback_handle_upload');

if ($this->form_validation->run() == FALSE) {
    $error_array = array(
        'pedido' => form_error('pedido'),
        'cliente' => form_error('cliente'),
        'motivo' => form_error('motivo'),
        'imagen' => form_error('imagen')
    );

    $this->session->set_userdata('notify', $error_array);
    redirect('garantias-y-devoluciones');
    die();
}
Run Code Online (Sandbox Code Playgroud)

这是我的回调函数

public function handle_upload($str)
{
    $this->form_validation->set_message('imagen', 'The {field} has an error.');
    return FALSE;
}
Run Code Online (Sandbox Code Playgroud)

它应该触发错误但不是.

AL *_* DI 10

解决了.​​!如果有人得到同样的错误,这就是我如何解决它,这是HMVC的一个错误"在将当前控制器作为$ CI变量分配给form_validation库之前.这将允许你的回调方法正常运行."

只需添加public $CIMY_Form_validation即可

然后在你的控制器构造函数上:

$this->load->library('form_validation');
        $this->form_validation->CI =& $this;
Run Code Online (Sandbox Code Playgroud)

更多信息在下面的页面:https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc