我正在开发一个需要一些建议的应用程序。这是问题的详细信息。
public function form()
{
$this->load->helper('inflector');
$id = $this->uri->segment(3,0);
if($data = $this->input->post()){
$result = $this->form_validation->run();
if($result){
if($id > 0){
// here update code
}else{
$this->mymodel->insert($data);
$this->session->set_flashdata('message','The page has been added successfully.');
$this->redirect = "mycontroller/index";
$this->view = FALSE;
}
}else{
//$this->call_post($data);
$this->session->set_flashdata('message','The Red fields are required');
$this->view = FALSE;
$this->redirect = "mycontroller/form/$id";
}
}else{
$row = $this->mymodel->fetch_row($id);
$this->data[]= $row;
}
}
public function _remap($method, $parameters)
{
if (method_exists($this, $method))
{
$return = call_user_func_array(array($this, $method),$parameters);
}else{
show_404();
}
if(strlen($this->view) > 0)
{
$this->template->build('default',array());
}else{
redirect($this->redirect);
}
}
在这里,您可以看到我如何尝试在验证失败时重新加载页面。现在的问题是我必须在视图表单上显示闪存数据,该数据仅在重定向后可用,并且我需要显示由于 post 变量丢失而在重定向时未显示的验证错误。如果我不使用重定向,则无法显示 flashdata,而只能显示验证错误。我希望将这两种功能结合在一起。我什至尝试过像这样再次创建 POST
public function call_post($data)
{
foreach($data as $key => $row){
$_POST[$key] = $row;
}
}
我在表单方法中注释掉了。我怎样才能做到这一点。