Skip to content

Commit

Permalink
add Flash back to Controller, fix Scaffold to use Flash instead
Browse files Browse the repository at this point in the history
  • Loading branch information
steinkel committed Nov 4, 2015
1 parent b9dc89a commit cb6a17c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Controller.php
Expand Up @@ -189,7 +189,7 @@ class Controller extends Object implements CakeEventListener {
* @var array
* @link http://book.cakephp.org/2.0/en/controllers/components.html
*/
public $components = array('Session');
public $components = array('Session', 'Flash');

/**
* The name of the View class this controller sends output to.
Expand Down
15 changes: 9 additions & 6 deletions lib/Cake/Controller/Scaffold.php
Expand Up @@ -145,7 +145,9 @@ public function __construct(Controller $controller, CakeRequest $request) {
$this->controller->viewClass = 'Scaffold';
}
$this->_validSession = (
isset($this->controller->Session) && $this->controller->Session->valid()
isset($this->controller->Session) &&
$this->controller->Session->valid() &&
isset($this->controller->Flash)
);
$this->_scaffold($request);
}
Expand Down Expand Up @@ -246,12 +248,12 @@ protected function _scaffoldSave(CakeRequest $request, $action = 'edit') {
Inflector::humanize($this->modelKey),
$success
);
return $this->_sendMessage($message);
return $this->_sendMessage($message, 'success');
}
return $this->controller->afterScaffoldSaveError($action);
}
if ($this->_validSession) {
$this->controller->Session->setFlash(__d('cake', 'Please correct errors below.'));
$this->controller->Flash->set(__d('cake', 'Please correct errors below.'));
}
}

Expand Down Expand Up @@ -303,7 +305,7 @@ protected function _scaffoldDelete(CakeRequest $request) {
}
if ($this->ScaffoldModel->delete()) {
$message = __d('cake', 'The %1$s with id: %2$s has been deleted.', Inflector::humanize($this->modelClass), $id);
return $this->_sendMessage($message);
return $this->_sendMessage($message, 'success');
}
$message = __d('cake',
'There was an error deleting the %1$s with id: %2$s',
Expand All @@ -321,11 +323,12 @@ protected function _scaffoldDelete(CakeRequest $request) {
* on the availability of a session
*
* @param string $message Message to display
* @param string $element Flash template to use
* @return void
*/
protected function _sendMessage($message) {
protected function _sendMessage($message, $element = 'default') {
if ($this->_validSession) {
$this->controller->Session->setFlash($message);
$this->controller->Flash->set($message, compact('element'));
return $this->controller->redirect($this->redirect);
}
$this->controller->flash($message, $this->redirect);
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Test/Case/Controller/ControllerTest.php
Expand Up @@ -993,6 +993,7 @@ public function testMergeVarsNotGreedy() {
$Controller->constructClasses();

$this->assertFalse(isset($Controller->Session));
$this->assertFalse(isset($Controller->Flash));
}

/**
Expand Down

0 comments on commit cb6a17c

Please sign in to comment.