2017-07-03 64 views
0

我試着創建一個驅動程序來驗證我的表單。所以,在CONTROLER我加載驅動程序,然後我的驗證形式,像這樣:CodeIgniter驅動程序和庫

控制器:

(...) 

    $this->load->driver('user'); 
    $this->user->register->validate_form($config); 
(...) 

司機:

public function validate_form($config){ 


     $this->form_validation->set_rules($config); 

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

(...) 

該錯誤消息:

消息:致電會員函數set_rules()在非對象上

任何人都知道什麼是問題? Form_validation被加載。

+0

爲什麼司機? https://www.codeigniter.com/userguide2/libraries/form_validation.html –

+0

是的,ideia在驅動程序中獲取form_validation庫。這個問題可能是。是否有可能在驅動程序內部獲得庫(loke form_validation)? –

回答

0

You just create a validation class like below 
 

 
<?php 
 
defined('BASEPATH') OR exit('No direct script access allowed'); 
 
class Validation{ 
 
\t public \t $v_required ='required|trim'; 
 

 
\t //Valid name 
 
\t public \t $v_name ='trim|min_length[3]|max_length[15]|regex_match[/^[A-Za-z][A-Za-z0-9 .]+$/]'; 
 
    public $v_name_msg=array('required'=>'Provide %s.','regex_match'=>'Must starts with alphabet,No special chars are allowed.'); 
 
} 
 
?> 
 
    
 
After call this to your controller like 
 
    
 
require_once(APPPATH."controllers/classes/Validation.php"); 
 
    
 
After creare a object and use validation class 
 
    
 
$da=new validation(); 
 
$this->form_validation->set_rules('name','Name',$da->v_name,$da->v_name_msg);