Skip to content
Permalink
Browse files

Fixing Scaffold not using session flashes even when they are available.

Simplifying message generation. Refs #64
  • Loading branch information...
markstory committed Aug 31, 2009
1 parent f6ce178 commit 71e93b9ae8a2a9f96f51d60f0f0bd08168b7f18f
Showing with 21 additions and 33 deletions.
  1. +21 −33 cake/libs/controller/scaffold.php
@@ -197,10 +197,10 @@ function __construct(&$controller, $params) {
if ($this->controller->view && $this->controller->view !== 'Theme') {
$this->controller->view = 'scaffold';
}
$this->__scaffold($params);
$this->_validSession = (
isset($this->controller->Session) && $this->controller->Session->valid() != false
);
$this->__scaffold($params);
}
/**
@@ -223,20 +223,15 @@ function _output() {
*/
function __scaffoldView($params) {
if ($this->controller->_beforeScaffold('view')) {
$message = sprintf(__("No id set for %s::view()", true), Inflector::humanize($this->modelKey));
if (isset($params['pass'][0])) {
$this->ScaffoldModel->id = $params['pass'][0];
} elseif ($this->_validSession) {
$this->controller->Session->setFlash(sprintf(
__("No id set for %s::view()", true),
Inflector::humanize($this->modelKey
)));
$this->controller->Session->setFlash($message);
$this->controller->redirect($this->redirect);
} else {
return $this->controller->flash(sprintf(
__("No id set for %s::view()", true), Inflector::humanize($this->modelKey)),
'/' . Inflector::underscore($this->controller->viewPath
));
return $this->controller->flash($message, '/' . Inflector::underscore($this->controller->viewPath));
}
$this->ScaffoldModel->recursive = 1;
$this->controller->data = $this->ScaffoldModel->read();
@@ -327,7 +322,7 @@ function __scaffoldSave($params = array(), $action = 'edit') {
if ($this->ScaffoldModel->save($this->controller->data)) {
if ($this->controller->_afterScaffoldSave($action)) {
$message = sprintf(__('The %1$s has been %2$s', true),
$message = sprintf(__('The %1$s has been %2$s', true),
Inflector::humanize($this->modelKey),
$success
);
@@ -384,46 +379,39 @@ function __scaffoldSave($params = array(), $action = 'edit') {
*/
function __scaffoldDelete($params = array()) {
if ($this->controller->_beforeScaffold('delete')) {
$message = sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey));
if (isset($params['pass'][0])) {
$id = $params['pass'][0];
} elseif ($this->_validSession) {
$this->controller->Session->setFlash(sprintf(
__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)
));
$this->controller->Session->setFlash($message);
$this->controller->redirect($this->redirect);
} else {
$this->controller->flash(sprintf(
__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)
), '/' . Inflector::underscore($this->controller->viewPath));
$this->controller->flash($message, '/' . Inflector::underscore($this->controller->viewPath));
return $this->_output();
}
if ($this->ScaffoldModel->delete($id)) {
$message = sprintf(
__('The %1$s with id: %2$d has been deleted.', true),
Inflector::humanize($this->modelClass), $id
);
if ($this->_validSession) {
$this->controller->Session->setFlash(sprintf(
__('The %1$s with id: %2$d has been deleted.', true),
Inflector::humanize($this->modelClass), $id
));
$this->controller->Session->setFlash($message);
$this->controller->redirect($this->redirect);
} else {
$this->controller->flash(sprintf(
__('The %1$s with id: %2$d has been deleted.', true),
Inflector::humanize($this->modelClass), $id
), '/' . $this->viewPath);
$this->controller->flash($message, '/' . $this->viewPath);
return $this->_output();
}
} else {
$message = sprintf(
__('There was an error deleting the %1$s with id: %2$d', true),
Inflector::humanize($this->modelClass), $id
);
if ($this->_validSession) {
$this->controller->Session->setFlash(sprintf(
__('There was an error deleting the %1$s with id: %2$d', true),
Inflector::humanize($this->modelClass), $id
));
$this->controller->Session->setFlash($message);
$this->controller->redirect($this->redirect);
} else {
$this->controller->flash(sprintf(
__('There was an error deleting the %1$s with id: %2$d', true),
Inflector::humanize($this->modelClass), $id
), '/' . $this->viewPath);
$this->controller->flash($message, '/' . $this->viewPath);
return $this->_output();
}
}

0 comments on commit 71e93b9

Please sign in to comment.
You can’t perform that action at this time.