Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed SessionHelper not handling stacked messages
- Loading branch information
1 parent
cdf00a9
commit 2e75f12
Showing
2 changed files
with
57 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,30 +134,14 @@ public function flash($key = 'flash', $attrs = array()) { | |
if (CakeSession::check('Message.' . $key)) { | ||
$flash = CakeSession::read('Message.' . $key); | ||
CakeSession::delete('Message.' . $key); | ||
$message = $flash['message']; | ||
unset($flash['message']); | ||
|
||
if (!empty($attrs)) { | ||
$flash = array_merge($flash, $attrs); | ||
} | ||
|
||
if ($flash['element'] === 'default') { | ||
$class = 'message'; | ||
if (!empty($flash['params']['class'])) { | ||
$class = $flash['params']['class']; | ||
$out = ''; | ||
foreach ($flash as $flashArray) { | ||
if (!empty($attrs)) { | ||
$flashArray = array_merge($flashArray, $attrs); | ||
} | ||
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>'; | ||
} elseif (!$flash['element']) { | ||
$out = $message; | ||
} else { | ||
$options = array(); | ||
if (isset($flash['params']['plugin'])) { | ||
$options['plugin'] = $flash['params']['plugin']; | ||
} | ||
$tmpVars = $flash['params']; | ||
$tmpVars['message'] = $message; | ||
$tmpVars['key'] = $key; | ||
$out = $this->_View->element($flash['element'], $tmpVars, $options); | ||
$flashArray['key'] = $key; | ||
$out .= $this->_render($flashArray); | ||
} | ||
} | ||
return $out; | ||
|
@@ -173,4 +157,34 @@ public function valid() { | |
return CakeSession::valid(); | ||
} | ||
|
||
/** | ||
* Renders a flash message | ||
* | ||
* @param array $flash Flash message array | ||
* @return string | ||
*/ | ||
protected function _render($flash) { | ||
$message = $flash['message']; | ||
unset($flash['message']); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jeremyharris
Author
Member
|
||
|
||
if ($flash['element'] === 'default') { | ||
$class = 'message'; | ||
if (!empty($flash['params']['class'])) { | ||
$class = $flash['params']['class']; | ||
} | ||
$out = '<div id="' . $flash['key'] . 'Message" class="' . $class . '">' . $message . '</div>'; | ||
} elseif (!$flash['element']) { | ||
$out = $message; | ||
} else { | ||
$options = array(); | ||
if (isset($flash['params']['plugin'])) { | ||
$options['plugin'] = $flash['params']['plugin']; | ||
} | ||
$tmpVars = $flash['params']; | ||
$tmpVars['message'] = $message; | ||
$tmpVars['key'] = $flash['key']; | ||
$out = $this->_View->element($flash['element'], $tmpVars, $options); | ||
} | ||
return $out; | ||
} | ||
} |
If
$flash
is a string, this will cause a fatal.