Search code examples
codeigniterhttp-redirectcodeigniter-2

Codeigniter redirect vs. load view


I previously used to always write $this->load->view() to load a view. I noticed that there is a problem with that especially when it comes to resubmission and URL in address bar. Instead I started using redirect('controller/function','refresh') to achieve the same thing. My question is: Is this an alright approach or is it frowned upon? I feel my code is much smoother this way but I would certainly like to know if this had any side effects later.

e.g. use case:

$id = $this->user_model->buildAccount($name, $email);

if(isset($id) && $id != '') {
    $this->session->set_userdata('id', $id);
    redirect('users/details');
} else {
    redirect('members/');
}

Solution

  • When it comes to CI any approach you take is okay, imho, your approach is just fine. In your code above where you redirect the user after creating session, you should also check for the validity of the session in your user/details function. Anyways, you have to call load->view() to load a view, be it in any function. So, doesn't matters where you load your view.