自定义验证规则不能在帮助程序中

自定义验证规则不能在帮助程序中

本文介绍了CodeIgniter:自定义验证规则不能在帮助程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个验证助手,它应该具有我的所有自定义验证规则。问题是,当我在表单验证中使用它们时,它们似乎被忽略。如果我移动在执行表单验证的控制器中的函数,一切都像一个魅力。我的验证助手是自动加载的。



有没有什么理由为什么我不能使用这些验证功能,如果我把它们放在帮手?感谢。

解决方案

帮助器和控制器中的函数显然不同。



创建 MY_Form_validation.php libraries / 中添加函数,最后设置规则而不 callback _

 <?php if(!defined('BASEPATH'))exit('不允许直接脚本访问); 

class MY_Form_validation extends CI_Form_validation {

/ * set_rule('custom_require')* /
function custom_require($ str){

return(bool)$ str;

}

}


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 ignored. If I move the functions in the controller that is doing the form validation, everything works like a charm. My validation helper is autoloaded.

Is there any reason why I can't seem to use these validation functions if I put them in a helper? Thanks.

解决方案

A function in a helper and a controller are different obviously.

Create an extended MY_Form_validation.php in your libraries/, add the functions there and finally set the rules without callback_ and just their function name.

Example:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {

    /* set_rule('custom_require') */
    function custom_require($str) {

        return (bool)$str;

    }

}

这篇关于CodeIgniter:自定义验证规则不能在帮助程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 06:04