Skip to content

Commit 2f5963e

Browse files
committed
Merge pull request cakephp#1496 from ravage84/else-clause-after-redirect
Removed else clauses after redirects and added return before redirect() ...
2 parents a64c205 + 4c13a39 commit 2f5963e

File tree

6 files changed

+14
-17
lines changed

6 files changed

+14
-17
lines changed

app/Controller/PagesController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function display() {
5656

5757
$count = count($path);
5858
if (!$count) {
59-
$this->redirect('/');
59+
return $this->redirect('/');
6060
}
6161
$page = $subpage = $title_for_layout = null;
6262

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

+8-10
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@
5858
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
5959
return $this->redirect(array('action' => 'index'));
6060
<?php else: ?>
61-
$this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.'), array('action' => 'index'));
61+
return $this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.'), array('action' => 'index'));
6262
<?php endif; ?>
63-
} else {
63+
}
6464
<?php if ($wannaUseSession): ?>
65-
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
65+
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
6666
<?php endif; ?>
67-
}
6867
}
6968
<?php
7069
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
@@ -101,13 +100,12 @@
101100
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
102101
return $this->redirect(array('action' => 'index'));
103102
<?php else: ?>
104-
$this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
103+
return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
105104
<?php endif; ?>
106-
} else {
105+
}
107106
<?php if ($wannaUseSession): ?>
108-
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
107+
$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
109108
<?php endif; ?>
110-
}
111109
} else {
112110
$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
113111
$this->request->data = $this-><?php echo $currentModelName; ?>->find('first', $options);
@@ -147,13 +145,13 @@
147145
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));
148146
return $this->redirect(array('action' => 'index'));
149147
<?php else: ?>
150-
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'), array('action' => 'index'));
148+
return $this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'), array('action' => 'index'));
151149
<?php endif; ?>
152150
}
153151
<?php if ($wannaUseSession): ?>
154152
$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'));
155153
<?php else: ?>
156-
$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'), array('action' => 'index'));
154+
return $this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'), array('action' => 'index'));
157155
<?php endif; ?>
158156
return $this->redirect(array('action' => 'index'));
159157
}

lib/Cake/Console/Templates/skel/Controller/PagesController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function display() {
5757

5858
$count = count($path);
5959
if (!$count) {
60-
$this->redirect('/');
60+
return $this->redirect('/');
6161
}
6262
$page = $subpage = $title_for_layout = null;
6363

lib/Cake/Controller/Scaffold.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,9 @@ protected function _scaffoldDelete(CakeRequest $request) {
329329
protected function _sendMessage($message) {
330330
if ($this->_validSession) {
331331
$this->controller->Session->setFlash($message);
332-
$this->controller->redirect($this->redirect);
333-
} else {
334-
$this->controller->flash($message, $this->redirect);
332+
return $this->controller->redirect($this->redirect);
335333
}
334+
$this->controller->flash($message, $this->redirect);
336335
}
337336

338337
/**

lib/Cake/Test/test_app/Controller/PagesController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function display() {
5757

5858
$count = count($path);
5959
if (!$count) {
60-
$this->redirect('/');
60+
return $this->redirect('/');
6161
}
6262
$page = $subpage = $titleForLayout = null;
6363

lib/Cake/Test/test_app/Controller/TestsAppsController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function set_action() {
4949
}
5050

5151
public function redirect_to() {
52-
$this->redirect('http://cakephp.org');
52+
return $this->redirect('http://cakephp.org');
5353
}
5454

5555
}

0 commit comments

Comments
 (0)