我有一页载有表格,任何用户提交数据时,数据都交给控制员,如果出现任何错误,则由控制人对验证进行核对,然后将数据传送给模型。
To redirect to the previous page from controller (if there is any validation error), I have the following code
redirect($this->input->post( redirect ));
以上编码是工作上的罚款,但问题是在将用户转至上页之后(该页包含表格),没有显示验证错误。
So would you please kindly tell me how to pass the validation error information through this "redirect" code I posted above and show the validation error message on that page?
预兆:
Solution:
在我的控制员中:
$redirect=$this->input->post( redirect ); // << for this I have- <input name="redirect" type="hidden" value="<?= $this->uri->uri_string() ?>" /> in my view file
$this->session->set_flashdata( errors , validation_errors());
redirect($this->input->post( redirect ));
In my view file:
<?php
if ($this->session->flashdata( errors )){ //change!
echo "<div class= error >";
echo $this->session->flashdata( errors );
echo "</div>";
}
?>
因此,我可以通过从控制人向上页的转头传递验证错误数据。