|
发表于 2010-9-14 15:30:13
|
显示全部楼层
晒一晒我的 form_validation 扩展
----------------------------------------------------------------
先新增目录 application/config/form_validation
在 form_validation 末尾新增方法:
PHP复制代码 function set_config_rules ($file_name)
{
$config = array();
if (file_exists(APPPATH . 'config/form_validation/' . strtolower($file_name) . EXT ))
{
include_once (APPPATH . 'config/form_validation/' . strtolower($file_name) . EXT );
} else
{
if (file_exists(APPPATH . 'config/form_validation/' . ucfirst(strtolower($file_name)) . EXT ))
{
include_once (APPPATH . 'config/form_validation/' . ucfirst(strtolower($file_name)) . EXT );
}
}
$this->_config_rules = $config;
} 复制代码
测试用例---验证文件名.php
PHP复制代码 $config = array(
'insert' => array(
array('field' => 'user_id', 'label' => 'lang:consumer_integral_log_user_id_field', 'rules' => 'trim|required|numeric'),
array('field' => 'about', 'label' => 'lang:consumer_integral_log_about_field', 'rules' => 'trim|required|min_length[2]|max_length[75]'),
),
'update' => array(
array('field' => 'user_id', 'label' => 'lang:consumer_integral_log_user_id_field', 'rules' => 'trim|required|numeric'),
array('field' => 'about', 'label' => 'lang:consumer_integral_log_about_field', 'rules' => 'trim|required|min_length[2]|max_length[75]'),
array('field' => 'state', 'label' => 'lang:consumer_integral_log_state_field', 'rules' => 'trim|required'),
)
); 复制代码
测试用例--语言包.php
PHP复制代码 $lang['consumer_integral_log_id_field'] = '消费者积分';
$lang['consumer_integral_log_about_field'] = '描述';
$lang['consumer_integral_log_state_field'] = '状态'; 复制代码
....省略...
测试用例--控制器.php
PHP复制代码 $this->load->library('form_validation');
$this->lang->load("语言包");
$this->form_validation->set_config_rules('验证文件名');
if ($this->form_validation->run('insert') == true)
{
///实现逻辑
} 复制代码 |
评分
-
查看全部评分
|