1

完毕

没有机会在控制器操作中使用 $this->form_validation->run() 两次吗?CodeIgniter 似乎只验证第一条规则。我想使用 $this->form_validation->run() 两次,因为我需要第二个验证规则的验证值;)。

$this->form_validation->set_rules(...);
if($this->form_validation->run() === true)
{
    $value = $this->..._model->get( ...);  //use of validated value
    $this->form_validation->set_rules(...); //use of $value
    if($this->form_validation->run() === true)
    {
        //...
    }
}
4

2 回答 2

0

加载时尝试为 form_validation 库分配别名?那可能会解决问题。

$this->load->library('form_validation','','validation1');
$this->validation1->set_rules(...);
if($this->validation1->run() === true)
{
    $value = $this->..._model->get( ...);  //use of validated value
    $this->load->library('form_validation','','validation2');
    $this->validation2->set_rules(...); //use of $value
    if($this->validation2->run() === true)
    {
        //...
    }
}
于 2013-01-29T18:31:30.007 回答
0

在核心文件 - CodeIgniter_2.1.3/system/libraries/Form_validation.php 添加一行

$this->_field_data = array();

在方法运行()中;

public function run($group = '')
    {
        // add this line for clear field data to use validation many times
        $this->_field_data = array();
于 2015-07-27T14:25:50.417 回答