2007年12月25日 星期二

Redirect with exit

If you do a redirect in CakePHP 1.1 you often have to add an exit() after the redirect statement to stop the script execution:

$this->redirect('controller/action');
exit();


Thanks to a small enhancement in CakePHP 1.2 in the form of an additional parameter for the redirect() function you can now do:

$this->redirect('controller/action', null, true);

It’s the same functionality as in the previous code snippet, but with the advantage that your code becomes testable (you cannot test a function which contains an exit(), as the exit() also stops the execution of the test).

沒有留言:

wibiya widget