{296} - 3.5.3.2 Flow Control
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.
<?php
function placeOrder() {
//Logic for finalizing order goes here
if($success) {
$this->redirect(‘/orders/thanks’);
} else {
$this->redirect(‘/orders/confirm’);
}
}
?>
<?phpfunction placeOrder() {//Logic for finalizing order goes hereif($success) {$this->redirect(‘/orders/thanks’);} else {$this->redirect(‘/orders/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.
This method does not exit() after a redirect unless you set the third parameter to true.
Similarly, the flash() method is used to direct a user to a new page after an operation. The flash() method is different in that it shows a message before passing the user on to another URL.
The first parameter should hold the message to be displayed, and the second parameter is a CakePHP-relative URL. CakePHP will display the $message for $pause seconds before forwarding the user on.
For in-page flash messages, be sure to check out SessionComponent’s setFlash() method.
{1393} - 3.5.3.2 Flow Control
Differences
| Lines: 1-42 | Lines: 1-2 | ||
| <title>Flow Control</title> | <title>Flow Control</title> | ||
| - | <div class="method"> redirect(string $url, integer $status, boolean $exit) </div> <p> 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. </p> <pre> <?php function placeOrder() { //Logic for finalizing order goes here if($success) { $this->redirect(‘/orders/thanks’); } else { $this->redirect(‘/orders/confirm’); } } ?> </pre> <p> 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. </p> <p> This method does not exit() after a redirect unless you set the third parameter to true. </p> <div class="method"> flash(string $message, string $url, integer $pause) </div> <p> Similarly, the flash() method is used to direct a user to a new page after an operation. The flash() method is different in that it shows a message before passing the user on to another URL. </p> <p> The first parameter should hold the message to be displayed, and the second parameter is a CakePHP-relative URL. CakePHP will display the $message for $pause seconds before forwarding the user on. </p> <p> For in-page flash messages, be sure to check out SessionComponent’s setFlash() method. </p> |
+ | <p></p> |
