Skip to content

Commit 4a37ad5

Browse files
committed
Added return before redirects
As recommended by the Cookbook: http://book.cakephp.org/2.0/en/development/testing.html#testing-controllers > When testing actions that contain redirect() and other code following the redirect it is generally a good idea to return when redirecting. The reason for this, is that redirect() is mocked in testing, and does not exit like normal. And instead of your code exiting, it will continue to run code following the redirect.
1 parent 8a81903 commit 4a37ad5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/Cake/Console/Templates/default/actions/controller_actions.ctp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
5757
<?php if ($wannaUseSession): ?>
5858
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
59-
$this->redirect(array('action' => 'index'));
59+
return $this->redirect(array('action' => 'index'));
6060
<?php else: ?>
6161
$this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.'), array('action' => 'index'));
6262
<?php endif; ?>
@@ -99,7 +99,7 @@
9999
if ($this-><?php echo $currentModelName; ?>->save($this->request->data)) {
100100
<?php if ($wannaUseSession): ?>
101101
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
102-
$this->redirect(array('action' => 'index'));
102+
return $this->redirect(array('action' => 'index'));
103103
<?php else: ?>
104104
$this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
105105
<?php endif; ?>
@@ -145,7 +145,7 @@
145145
if ($this-><?php echo $currentModelName; ?>->delete()) {
146146
<?php if ($wannaUseSession): ?>
147147
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));
148-
$this->redirect(array('action' => 'index'));
148+
return $this->redirect(array('action' => 'index'));
149149
<?php else: ?>
150150
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'), array('action' => 'index'));
151151
<?php endif; ?>
@@ -155,5 +155,5 @@
155155
<?php else: ?>
156156
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'), array('action' => 'index'));
157157
<?php endif; ?>
158-
$this->redirect(array('action' => 'index'));
158+
return $this->redirect(array('action' => 'index'));
159159
}

0 commit comments

Comments
 (0)