3.5.3.2.1 redirect
redirect(string $url, integer $status, boolean $exit)
redirect()应该是你最经常使用的流程控制的方法之一。该方法接收的第一个参数是CakePHP形式的相对URL。当用户成功地下了订单之后,你也许会希望将他带到收款台前执行下一步操作。
function placeOrder() {
//这里是订单部分的逻辑
if($success) {
$this->redirect(array('controller' => 'orders', 'action' => 'thanks'));
} else {
$this->redirect(array('controller' => 'orders', 'action' => 'confirm'));
}
}
function placeOrder() {//这里是订单部分的逻辑if($success) {$this->redirect(array('controller' => 'orders', 'action' => 'thanks'));} else {$this->redirect(array('controller' => 'orders', 'action' => 'confirm'));}}
redirect()接收的第二个参数允许你定义一个HTTP的状态码(status code)比如视具体情况,你可能选择用301(永久性转移)或者303(see other)。
在第三参数没有被设定为false的情况下,重定向结束之后该方法会自动调用exit()结束程序。
See comments for this section
