3.5.3.2.1 redirect
redirect(string $url, integer $status, boolean $exit)
The flow control method you’ll use most often is redirect(). This method takes its first parameter in the form of a CakePHP-relative URL. When a user has successfully placed an order, you might wish to redirect them to a receipt screen.
function placeOrder() {
//Logic for finalizing order goes here
if($success) {
$this->redirect(array('controller' => 'orders', 'action' => 'thanks'));
} else {
$this->redirect(array('controller' => 'orders', 'action' => 'confirm'));
}
}
function placeOrder() {//Logic for finalizing order goes hereif($success) {$this->redirect(array('controller' => 'orders', 'action' => 'thanks'));} else {$this->redirect(array('controller' => 'orders', 'action' => 'confirm'));}}
The second parameter of redirect() allows you to define an HTTP status code to accompany the redirect. You may want to use 301 (moved permanently) or 303 (see other), depending on the nature of the redirect.
The method will issue an exit() after the redirect unless you set the third parameter to false.
