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.

Redirecting to the home page

Sometimes you’d like to create a link that will redirect your traffic to the homepage. For example, you have some partner web site that will drive traffic to a URL like: http://www.yoursite.com/partnerName. This way you’ll be able to track this link in the web site logs.

Just add the following line to your routes.php file:

 Router::connect('/partnerName', array('controller' => 'pages', 'action' => 'display', 'home'));