保定网站建设,网站推广,网站优化服务,保定专业的PHP网站制作机构!

CakePHP使用redirect后会停止执行后面的代码吗

发表于:2008年10月08日 16时  作者:dx_andy

CakePHP中$this->Model->redirect(url)后会执行其后面的代码吗?为此我进行了如下测试:

CakePHP Action代码

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)同)。