views:

41

answers:

2

I.e. would you recommend me to use one controller method like this:

function save()
{
    if(!is_bool($this->input->post(''))
    {
        $post_data = $this->input->post('');
        $this->mymodel->save($post_data);
    }
    $this->load->view('myview');
}

Or would you recommend writing it using two methods?

function save()
{
    if(!is_bool($this->input->post(''))
    {
        $post_data = $this->input->post('');
        $this->mymodel->save($post_data);
    }
    redirect('controller/method2')
}

The redirect is the crucial difference here. It prohibits resubmissions from update for example.

How do you do it? Is there another better way?

+2  A: 

You should always redirect on a successful form post.

Aren
+1  A: 

As Aren B said, redirection is a good idea, but what I would change in your code is that validation of the post data should be done with the form validation functionallity. It is not only more reauseable but the code will get shorter.

If you want to handle AJAX requests, you would need to return something else than a via or a redirection.

DrColossos