Skip to content
Permalink
Browse files

add Flash back to Controller, fix Scaffold to use Flash instead

  • Loading branch information...
steinkel committed Nov 4, 2015
1 parent b9dc89a commit cb6a17c34ee4ad348d512a805a259b5ff7d7596e
@@ -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.
@@ -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);
}
@@ -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.'));
}
}
@@ -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',
@@ -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);
@@ -993,6 +993,7 @@ public function testMergeVarsNotGreedy() {
$Controller->constructClasses();
$this->assertFalse(isset($Controller->Session));
$this->assertFalse(isset($Controller->Flash));
}
/**

0 comments on commit cb6a17c

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