Merge pull request #7642 from steinkel/issue/missing-flash-bake-and-scaffold

add Flash back to Controller, fix Scaffold to use Flash instead
This commit is contained in:
Mark Story 2015-11-04 21:27:26 -05:00
commit e7eeafcddd
3 changed files with 11 additions and 7 deletions

View file

@ -189,7 +189,7 @@ class Controller extends Object implements CakeEventListener {
* @var array * @var array
* @link http://book.cakephp.org/2.0/en/controllers/components.html * @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. * The name of the View class this controller sends output to.

View file

@ -145,7 +145,9 @@ class Scaffold {
$this->controller->viewClass = 'Scaffold'; $this->controller->viewClass = 'Scaffold';
} }
$this->_validSession = ( $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); $this->_scaffold($request);
} }
@ -246,12 +248,12 @@ class Scaffold {
Inflector::humanize($this->modelKey), Inflector::humanize($this->modelKey),
$success $success
); );
return $this->_sendMessage($message); return $this->_sendMessage($message, 'success');
} }
return $this->controller->afterScaffoldSaveError($action); return $this->controller->afterScaffoldSaveError($action);
} }
if ($this->_validSession) { 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 @@ class Scaffold {
} }
if ($this->ScaffoldModel->delete()) { if ($this->ScaffoldModel->delete()) {
$message = __d('cake', 'The %1$s with id: %2$s has been deleted.', Inflector::humanize($this->modelClass), $id); $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', $message = __d('cake',
'There was an error deleting the %1$s with id: %2$s', 'There was an error deleting the %1$s with id: %2$s',
@ -321,11 +323,12 @@ class Scaffold {
* on the availability of a session * on the availability of a session
* *
* @param string $message Message to display * @param string $message Message to display
* @param string $element Flash template to use
* @return void * @return void
*/ */
protected function _sendMessage($message) { protected function _sendMessage($message, $element = 'default') {
if ($this->_validSession) { if ($this->_validSession) {
$this->controller->Session->setFlash($message); $this->controller->Flash->set($message, compact('element'));
return $this->controller->redirect($this->redirect); return $this->controller->redirect($this->redirect);
} }
$this->controller->flash($message, $this->redirect); $this->controller->flash($message, $this->redirect);

View file

@ -993,6 +993,7 @@ class ControllerTest extends CakeTestCase {
$Controller->constructClasses(); $Controller->constructClasses();
$this->assertFalse(isset($Controller->Session)); $this->assertFalse(isset($Controller->Session));
$this->assertFalse(isset($Controller->Flash));
} }
/** /**