Codeigniter when to use redirect() and when to use $this->load->view

T-Wrecks picture T-Wrecks · Nov 26, 2010 · Viewed 8.3k times · Source

I am fairly new to Codeigniter and I am wondering on some Codeigniter best practices. When should i use redirect() versus using

$this->load->view

It seems that when I use redirect() then $this->session->set_flashdata works like it should but when i use

$this->load->view

the message is displayed after an additional request.

Answer

fred picture fred · Nov 26, 2010

I think you really answered your own question.

Use redirect() when a simple flash message at the top of another page is an appropriate response, use $this->load->view() when you're providing an entire page worth of feedback for whatever the incoming request may be.

So for example, when a new user signs up the "Success" page would be a loaded view and perhaps when a user edits something in their account a flash message "Changes saved" or soemthing similar on the same page is sufficient.