纳尼啦 发表于 2016-11-4 20:47:19

form_validation 第四个参数设置自定义错误

form_validation 第四个参数设置自定义错误,为什么不能够生效

$this->form_validation->set_rules('password', 'Password', 'trim|required' , array('required'=> '*必选项') );

纳尼啦 发表于 2016-11-5 13:34:46

      //validate form input
      $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length|max_length|xss_clean' ,
                array('min_length'=> '*5~12个字符',
                        'max_length'=> '*5~12个字符',
                        'required'=> '*必选项',
                )
      );
      $this->form_validation->set_rules('password', 'Password', 'trim|required' ,
                array('required'=> '*必选项',
                )
      );
      
//         $this->form_validation->set_message('required', '*必选项');
//         $this->form_validation->set_message('min_length', '*5~12个字符');
//         $this->form_validation->set_message('max_length', '*5~12个字符');

纳尼啦 发表于 2016-11-7 15:19:53

Hex 发表于 2016-11-7 14:51
看了一下,这个类库扩展的太多了,你可以说说你的具体需求,为什么要扩展系统的类库呢? ...

/**
   * Executes the Validation routines
   *
   * Modified to work with HMVC -- Phil Sturgeon
   * Modified to work with callbacks in the calling model -- Jerel Unruh
   *
   * @access    private
   * @param    array
   * @param    array
   * @param    mixed
   * @param    integer
   * @return    mixed
   */
    protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)

其他一些函数只是自定义的验证规则和一些系统规则的重写,这个函数的执行造成了set_rules 第四个参数无效,这个函数的覆盖是为了适应HMVC的系统架构和错误输出,以及自定义回调函数的调用路径规则。大概是这样的,可能不准确

纳尼啦 发表于 2016-11-7 09:55:35

Hex 发表于 2016-11-6 23:13
看起来你写的没问题。重新下载一个干净的 CI 试试?

找到原因了 ,
class My_Form_validation extends CI_Form_validation
这个是集成CI_Form_validation ,放在libraries/目录下
不过我不明白的是 $this->load->library('form_validation'); 为什么能够直接引用这个自定义的,而不是系统库

Hex 发表于 2016-11-4 22:34:14

你的代码逗号好像有问题吧。。。。

纳尼啦 发表于 2016-11-5 11:16:37

Hex 发表于 2016-11-4 22:34
你的代码逗号好像有问题吧。。。。

谢谢回复,是我抄的时候逗号抄错了。在程序里调试,没有语法错误的。
我看官方文档也是有这种用法的,就是不能生效。只能set_message 为单个规则设置错误提示信息

Hex 发表于 2016-11-6 17:17:00

你的 CI 版本是什么?

纳尼啦 发表于 2016-11-6 20:29:53

Hex 发表于 2016-11-6 17:17
你的 CI 版本是什么?

3.0+ ,然后我试了一下把内核升级到3.12最新版本,也没有什么用

纳尼啦 发表于 2016-11-6 20:51:29

纳尼啦 发表于 2016-11-5 11:16
谢谢回复,是我抄的时候逗号抄错了。在程序里调试,没有语法错误的。
我看官方文档也是有这种用法的,就 ...

$this->load->library('form_validation');
这是我引用的系统库

Hex 发表于 2016-11-6 23:13:31

纳尼啦 发表于 2016-11-6 20:51
这是我引用的系统库

看起来你写的没问题。重新下载一个干净的 CI 试试?

Hex 发表于 2016-11-7 13:46:11

纳尼啦 发表于 2016-11-7 09:55
找到原因了 ,

这个是集成CI_Form_validation ,放在libraries/目录下

对呀,这就是 CI 扩展类库的方式,也就是说你扩展了类库,就没法使用系统原来的类库了,手册里有说明如何使用扩展类库。http://codeigniter.org.cn/user_guide/general/core_classes.html
页: [1] 2
查看完整版本: form_validation 第四个参数设置自定义错误