From 9e1019787b7af51cb0bbf15dd11e168667ffb9a4 Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 31 Mar 2007 19:37:59 +0000 Subject: [PATCH] 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 --- cake/libs/controller/components/session.php | 29 +++------------------ cake/libs/view/helpers/session.php | 17 ++++++++++-- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/cake/libs/controller/components/session.php b/cake/libs/controller/components/session.php index 24f0036c2..eec3f94ab 100644 --- a/cake/libs/controller/components/session.php +++ b/cake/libs/controller/components/session.php @@ -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 = '
' . $flashMessage . '
'; - } 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')); } } /** diff --git a/cake/libs/view/helpers/session.php b/cake/libs/view/helpers/session.php index d2e762ffa..836e16357 100644 --- a/cake/libs/view/helpers/session.php +++ b/cake/libs/view/helpers/session.php @@ -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 = '
' . $flash['message'] . '
'; + } 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(); } } }