完成
是否有机会在控制器操作中两次使用$ 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)
{
//...
}
}
答案 0 :(得分: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)
{
//...
}
}
答案 1 :(得分:0)
在核心文件中 - CodeIgniter_2.1.3 / system / libraries / Form_validation.php 添加一行
$this->_field_data = array();
方法run(); 中的
public function run($group = '')
{
// add this line for clear field data to use validation many times
$this->_field_data = array();