Skip to content

Commit 86f2008

Browse files
committed
Merge branch '1.2' of dev@code.cakephp.org:cakephp into 1.2
2 parents 3cdf89d + a678a60 commit 86f2008

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

cake/libs/controller/scaffold.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,12 @@ function __scaffoldSave($params = array(), $action = 'edit') {
267267
}
268268

269269
if (!$this->ScaffoldModel->exists()) {
270+
$message = sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey));
270271
if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
271-
$this->controller->Session->setFlash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey)));
272+
$this->controller->Session->setFlash($message);
272273
$this->controller->redirect($this->redirect);
273274
} else {
274-
return $this->controller->flash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey)), $this->redirect);
275+
return $this->controller->flash($message, $this->redirect);
275276
}
276277
}
277278
}
@@ -283,11 +284,16 @@ function __scaffoldSave($params = array(), $action = 'edit') {
283284

284285
if ($this->ScaffoldModel->save($this->controller->data)) {
285286
if ($this->controller->_afterScaffoldSave($action)) {
287+
$message = sprintf(__('The %1$s has been %2$s', true),
288+
Inflector::humanize($this->modelKey),
289+
$success
290+
);
286291
if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
287-
$this->controller->Session->setFlash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success));
292+
$this->controller->Session->setFlash($message);
288293
$this->controller->redirect($this->redirect);
289294
} else {
290-
return $this->controller->flash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success), $this->redirect);
295+
$this->controller->flash($message, $this->redirect);
296+
return $this->_output();
291297
}
292298
} else {
293299
return $this->controller->_afterScaffoldSaveError($action);
@@ -336,23 +342,25 @@ function __scaffoldDelete($params = array()) {
336342
$this->controller->Session->setFlash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)));
337343
$this->controller->redirect($this->redirect);
338344
} else {
339-
return $this->controller->flash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)),
340-
'/' . Inflector::underscore($this->controller->viewPath));
345+
$this->controller->flash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)), '/' . Inflector::underscore($this->controller->viewPath));
346+
return $this->_output();
341347
}
342348

343349
if ($this->ScaffoldModel->del($id)) {
344350
if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
345351
$this->controller->Session->setFlash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id));
346352
$this->controller->redirect($this->redirect);
347353
} else {
348-
return $this->controller->flash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
354+
$this->controller->flash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
355+
return $this->_output();
349356
}
350357
} else {
351358
if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
352359
$this->controller->Session->setFlash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id));
353360
$this->controller->redirect($this->redirect);
354361
} else {
355-
return $this->controller->flash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
362+
$this->controller->flash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
363+
return $this->_output();
356364
}
357365
}
358366
} elseif ($this->controller->_scaffoldError('delete') === false) {

cake/tests/cases/libs/controller/scaffold.test.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,45 @@ function testScaffoldVariableSetting() {
676676
$this->assertEqual($result['pluralVar'], 'scaffoldMock');
677677
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
678678
}
679+
/**
680+
* test that scaffold outputs flash messages when sessions are unset.
681+
*
682+
* @return void
683+
**/
684+
function testScaffoldFlashMessages() {
685+
$this->Controller->action = 'edit';
686+
$this->Controller->here = '/scaffold_mock';
687+
$this->Controller->webroot = '/';
688+
$params = array(
689+
'plugin' => null,
690+
'pass' => array(1),
691+
'form' => array(),
692+
'named' => array(),
693+
'url' => array('url' =>'scaffold_mock'),
694+
'controller' => 'scaffold_mock',
695+
'action' => 'edit',
696+
);
697+
//set router.
698+
Router::reload();
699+
Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/')));
700+
$this->Controller->params = $params;
701+
$this->Controller->controller = 'scaffold_mock';
702+
$this->Controller->base = '/';
703+
$this->Controller->data = array(
704+
'ScaffoldMock' => array(
705+
'id' => 1,
706+
'title' => 'New title',
707+
'body' => 'new body'
708+
)
709+
);
710+
$this->Controller->constructClasses();
711+
unset($this->Controller->Session);
712+
713+
ob_start();
714+
new Scaffold($this->Controller, $params);
715+
$result = ob_get_clean();
716+
$this->assertPattern('/Scaffold Mock has been updated/', $result);
717+
}
679718
/**
680719
* test that habtm relationship keys get added to scaffoldFields.
681720
*

0 commit comments

Comments
 (0)