Moving session flash rendering from component to helper (fixes errors when using setFlash() in beforeFilter)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4719 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-03-31 19:37:59 +00:00
parent e569b97867
commit 9e1019787b
2 changed files with 18 additions and 28 deletions

View file

@ -172,37 +172,14 @@ class SessionComponent extends CakeSession {
*
* Additional params below can be passed to customize the output, or the Message.[key]
*
* @param string $flashMessage Message to be flashed
* @param string $message Message to be flashed
* @param string $layout Layout to wrap flash message in
* @param array $params Parameters to be sent to layout as view variables
* @param string $key Message key, default is 'flash'
*/
function setFlash($flashMessage, $layout = 'default', $params = array(), $key = 'flash') {
function setFlash($message, $layout = 'default', $params = array(), $key = 'flash') {
if ($this->__active === true) {
if ($layout == 'default') {
$out = '<div id="' . $key . 'Message" class="message">' . $flashMessage . '</div>';
} elseif ($layout == '' || $layout == null) {
$out = $flashMessage;
} else {
$ctrl = null;
$view = new View($ctrl);
$view->base = $this->base;
$view->webroot = $this->webroot;
$view->here = $this->here;
$view->params = $this->params;
$view->action = $this->action;
$view->data = $this->data;
$view->themeWeb = '';
$view->plugin = $this->plugin;
$view->namedArgs = array();
$view->argSeparator = array();
$view->helpers = array('Html');
$view->layout = $layout;
$view->pageTitle = '';
$view->viewVars = $params;
$out = $view->renderLayout($flashMessage);
}
$this->write('Message.' . $key, $out);
$this->write('Message.' . $key, compact('message', 'layout', 'params'));
}
}
/**

View file

@ -115,7 +115,20 @@ class SessionHelper extends CakeSession {
function flash($key = 'flash') {
if ($this->__active === true) {
if (parent::check('Message.' . $key)) {
e(parent::read('Message.' . $key));
$flash = parent::read('Message.' . $key);
if ($flash['layout'] == 'default') {
$out = '<div id="' . $key . 'Message" class="message">' . $flash['message'] . '</div>';
} elseif ($flash['layout'] == '' || $flash['layout'] == null) {
$out = $flash['message'];
} else {
$view =& ClassRegistry::getObject('view');
list($tmpLayout, $tmpVars, $tmpTitle) = array($view->layout, $view->viewVars, $view->pageTitle);
list($view->layout, $view->viewVars, $view->pageTitle) = array($flash['layout'], $flash['params'], '');
$out = $view->renderLayout($flash['message']);
list($view->layout, $view->viewVars, $view->pageTitle) = array($tmpLayout, $tmpVars, $tmpTitle);
}
e($out);
parent::del('Message.' . $key);
return true;
}
@ -129,7 +142,7 @@ class SessionHelper extends CakeSession {
*/
function valid() {
if ($this->__active === true) {
return parent::valid();
return parent::valid();
}
}
}