CakePHP中$this->Model->redirect(url)后会执行其后面的代码吗?为此我进行了如下测试:
function index() {
$this->redirect(‘/news/view/’);
$this->redirect(‘/news/edit/’);
}
执行上面代码,没有按我的预计想法执行(跳转到view里),而是跳转到了edit里。由此可见$this->Model->redirect(url);后CakePHP并没有为我们加入exit();方法,它会继续执行其后的代码。
所以建议使用中,如果$this->Model->redirect(url);后我们不想让其后面的代码执行的话,应该手动为其加上exit();方法,即:$this->Model->redirect(url);exit(); ($this->render(view)同)。