2017-08-29 49 views
0

// 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'); 
    } 

//負荷數組保存數據的輸入和檢查輸入,然後保存數據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); 
} 

} 











} 
+0

詞不等於CI。確保$ this-> ci是$ this-> CI –

回答

0

請檢查您form_validation庫加載與否

:你需要改變這種狀況

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); 
} 

} 
+0

它的保存數據沒有檢查 – NewPhpProgramer101

+0

請檢查我更新的代碼 – NewPhpProgramer101