1

I have one form in my view.php file. Its URL like https://example.com/members/view/1, https://example.com/members/view/2 etc. When I submit form its calling model through controller like below

public function insert_comments(){



        $data=$this->input->post();



        $this->load->model('work_model');



        $result=$this->work_model->insert_comments($data);



        if($result)



        {
                $this->session->set_flashdata('insert_comments','your comments succesfully');

                $this->session->set_flashdata('succesfully','alert-success');

                $this->load->view('add_coments');

        }

        else{


            $this->session->set_flashdata('insert_comments','your comments failed');

                $this->session->set_flashdata('succesfully','alert-danger');

                $this->load->view('add_coments');

        }

    }

}

and model is like below

public function insert_comments($array)

{

    return $this->db->insert('comments',$array);

}

Currently its working fine and on form submit its loding view called add_comments, instead I want reload/refresh current page. I am not able to get idea of how I can do it, let me know if someone can help me for do it.

Thanks!

rajrathod
  • 89
  • 8

3 Answers3

1

According to this answer, in the controller you can use:

redirect($this->uri->uri_string());
Giacomo M
  • 4,450
  • 7
  • 28
  • 57
0

use this :

redirect($_SERVER['REQUEST_URI'], 'refresh'); 
0

Whenever you are reloading or redirecting a page you should always use the redirect() method instead of loading a view.

Redirection basically uses the header() method of core PHP and redirection will never execute the code blocks written beyond the redirect() method. But in the case of loading the view, it can execute until the end of the code block.

In your code, replace the line $this->load->view('add_coments'); with the redirection to the desired controller

redirect('your-controller','refresh');

I hope that helps you.

BEingprabhU
  • 1,618
  • 2
  • 21
  • 28