南宫云尚 发表于 2012-2-4 17:20:33

form_validation 的扩展程序

大家都用过form_validation的表单验证工作,想来很方便。但是作为现在安全要求越来越高,我们就需要不断的扩展为我们你的网站安全。特别是B2C类网站。下面我介绍一下一个新的扩展方式,不只是局限于form_validation的一个文件功能,实现多文件,多验证的功能。
在system/libraies/form_validation.php文件添加
function set_config_rules($file_name)
    {
      $config = array();
                $app_file = $this->CI->config->item('form_validation');
                $app_file=$app_file.'/';
      if (file_exists($app_file . strtolower($file_name) . EXT))
      {
            include_once ($app_file . strtolower($file_name) . EXT);
      } else
      {
            if (file_exists($app_file . ucfirst(strtolower($file_name)) . EXT))
            {
                include_once ($app_file. ucfirst(strtolower($file_name)) . EXT);
            } else
            {
                log_message('error', 'form validation config rules file not exists!');
            }
      }
      $this->_config_rules = $config;
    }

再在配置文件配置 form_validation 对应的文件夹。然后加载改文件,实现多个文件验证。
页: [1]
查看完整版本: form_validation 的扩展程序