另一个解决方案是 扩展库 。该属性受到保护,因此我们可以访问它:CI_Form_validation
$_field_data
class MY_Form_validation extends CI_Form_validation {
public function __construct()
{
parent::__construct();
}
public function clear_field_data() {
$this->_field_data = array();
return $this;
}
}
并调用新方法。这样,您就可以传递数据,而无需在会话中存储数据。
class Item extends Controller
{
function Item()
{
parent::Controller();
}
function add()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'name', 'required');
$success = false;
if ($this->form_validation->run())
{
$success = true;
$this->form_validation->clear_field_data();
}
$this->load->view('item/add', array('success' => $success));
}
}