CodeIgniter驱动程序和库
问题描述:
我试着创建一个驱动程序来验证我的表单。所以,在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被加载。
答
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);
为什么司机? https://www.codeigniter.com/userguide2/libraries/form_validation.html –
是的,ideia在驱动程序中获取form_validation库。这个问题可能是。是否有可能在驱动程序内部获得库(loke form_validation)? –