CodeIgniter: custom validation rules can't be in a helper?

后端 未结 2 1226
执笔经年
执笔经年 2021-01-16 14:04

I\'ve created a \"validation helper\" that was supposed to have all my custom validation rules. The problem is that when I use them in my form validation, they seem to be ig

2条回答
  •  悲哀的现实
    2021-01-16 14:18

    Robin's answer is the easiest way to deal with it; however, the why you can't is this:

    look in your system/libraries/Form_Validation.php, line: 587

    if ( ! method_exists($this->CI, $rule))
    {
      continue;
    }
    

    This check is done on all callbacks. Helpers are not classes & not loaded into the CI instance - and so not available from the Form_Validation library (because of the way it is specifically coded in this method)

提交回复
热议问题