简体   繁体   English

如何在Codeigniter的自定义库中设置规则形式验证

[英]how to set rules form validation in my custom library in codeigniter

// iam trying to load array with input and checking the input then save the data // iam尝试使用输入加载数组并检查输入,然后保存数据

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Slider{

      public $ci;
       public $ci2;
        protected $CI;
     function __construct() {
                 // reference to the CodeIgniter super object 
         $this->CI =& get_instance();
             $this->ci =&get_instance();
           $this->ci->load->model('Slider_Model');
                   $this->CI->load->library('form_validation');
    }

//load array with input and checking the input then save the data enter image description here //使用输入加载数组并检查输入,然后保存数据, 在此处输入图像描述

       function AddSlide($Data){
$this->CI->load->library('form_validation');
$this->CI->form_validation->set_error_delimiters('<p style="color: red">', '</p>');
$this->CI->form_validation->set_rules($Data['Title'],$Data['Title'],'min_length[5]|max_length[20]'); 
$this->CI->form_validation->set_rules($Data['Description'],$Data['Description'],'min_length[10]|max_length[100]'); 
$this->CI->form_validation->set_rules($Data['Status'],$Data['Status'],'in_list[1,2]');

if ($this->CI->form_validation->run() == FALSE)
{
   echo FALSE;
}
else
{
   $this->ci->Slider_Model->AddNewSlid($Data);
}

}











}

please check that your form_validation library is loaded or not 请检查您的form_validation库是否已加载

You should need to change this condition 您应该更改此条件

if ($this->CI->form_validation->run() === FALSE) 

to this if ($this->CI->form_validation->run() == FALSE) 对此if ($this->CI->form_validation->run() == FALSE)

function AddSlide($Data)
{ 
$this->load->library('form_validation');

$this->form_validation->set_error_delimiters('<p style="color: red">', '</p>');
$this->CI->form_validation->set_rules($Data['Title'],'sasass','min_length[5]|max_length[20]'); 
$this->CI->form_validation->set_rules($Data['decription'],$Data['decription'],'min_length[10]|max_length[100]'); 
$this->CI->form_validation->set_rules($Data['status'],$Data['status'],'in_list[1,2]');

if ($this->CI->form_validation->run() == FALSE)
{
   echo FALSE;
}
else
{
   $this->ci->Slider_Model->AddNewSlid($Data);
}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM