0

i have a php page where i have a link which calls a controller function page_view. within that controller function there are some codes which retrieve data using models and store in variable data then a view is loaded as $this->load->view('common/view_plan',$data);

in the view_plan page there is a form. when this form is submitted the data in the form is to be saved and then should get redirected to the same view_plan. so i wrote a controller function to save the data. but how can i redirect to the same page. can i call the controller function page_view from another controller

beginner
  • 29
  • 1
  • 5
  • You should [use PRG](https://stackoverflow.com/questions/10827242/understanding-the-post-redirect-get-pattern) so that if the user hits reload they don't just resubmit the data again, and so after storing your data you should [`redirect()`](https://codeigniter.com/user_guide/helpers/url_helper.html#redirect) back the whatever the URL of the view_plan is. – Don't Panic Nov 06 '19 at 17:08

1 Answers1

0

If you are submitting and showing the form in the same method of the same controller you could do something like this:

public function view_page() {
   if (!empty($_POST)) {
      // your form submission logic here
   }

   // your regular steps with fetching data from model and showing in the view
   $this->load->view('common/view_plan',$data);
}
Mehedi Hassan
  • 376
  • 3
  • 10