codeigniter use of redirect() codeigniter use of redirect() codeigniter codeigniter

codeigniter use of redirect()


It's bad practice to use redirects like that; you're basically doubling the # of server requests.

If you don't want to have the function names in the URL, just have the form POST to the controller index() function, and call the function you need based on some criteria such as what was passed from the forms POST data:

<form action="myapp.com/controller_name" method="post">

Controller:

function index(){        if(!empty($_POST['some_form_data'])){            $this->page_feature();        }       else{            $this->load->view('page');        }}function page_feature(){       /* some stuff */       $this->load->view('page_feature');}

You may also want to check out the _remap() function. That way additional uri segments are not treated as function calls.


Redirection is most useful to prevent users from resubmitting form data. If you just display your output at the same URL you submit to, users refreshing the page will always get a prompt asking them to resubmit the form.

Redirecting also impacts the performance by making the client perform one more request to the server, but that's probably negligible in most situations.