Food for thought: $this->redirect() vs $this->render()

One example, that we often see, is something along the following lines in the controller:

if($this->User->save($this->data)) {
  $this->Session->setFlash(... some stuff for the view ... );
  $this->redirect(array('action'=>'success'));
}

If all we are doing is displaying a “success” page back to the user, do we really need to bother with a redirect()?

To me it seems a little easier to do:

if($this->User->save($this->data)) {
  $this->set('arrayOfMessages', $myPreviouslyPreparedArrayOfMessages);
  $this->render('success');
}

Not really a big deal one way or another, but something to consider (especially for those very high traffic servers ;)).

P.S. As some readers pointed out, the obvious draw back is that $this->render() will cause the data re-submit prompts when refreshing or going back in the browser.

Related Posts

%d bloggers like this: