Skip to content
Permalink
Browse files

Updating SessionHelper::flash() to use elements for custom flash wrap…

…ping html instead of layouts.
  • Loading branch information...
markstory committed Sep 1, 2009
1 parent 17e81ab commit 4d458e93b6fe741e2b066faeadd86fff9e3e2d04
@@ -1,8 +1,6 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
* Session Helper provides access to the Session in the Views.
*
* Long description for file
*
@@ -15,14 +13,11 @@
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.view.helpers
* @since CakePHP(tm) v 1.1.7.3328
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
if (!class_exists('cakesession')) {
@@ -139,21 +134,20 @@ function flash($key = 'flash') {
if (parent::check('Message.' . $key)) {
$flash = parent::read('Message.' . $key);
if ($flash['layout'] == 'default') {
if ($flash['element'] == 'default') {
if (!empty($flash['params']['class'])) {
$class = $flash['params']['class'];
} else {
$class = 'message';
}
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>';
} elseif ($flash['layout'] == '' || $flash['layout'] == null) {
} elseif ($flash['element'] == '' || $flash['element'] == null) {
$out = $flash['message'];
} else {
$view =& ClassRegistry::getObject('view');
list($tmpVars, $tmpTitle) = array($view->viewVars, $view->pageTitle);
list($view->viewVars, $view->pageTitle) = array($flash['params'], '');
$out = $view->renderLayout($flash['message'], $flash['layout']);
list($view->viewVars, $view->pageTitle) = array($tmpVars, $tmpTitle);
$tmpVars = $flash['params'];
$tmpVars['message'] = $flash['message'];
$out = $view->element($flash['element'], $tmpVars);
}
echo($out);
parent::del('Message.' . $key);
@@ -1,6 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* SessionHelperTest file
*
@@ -9,20 +7,17 @@
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs.view.helpers
* @since CakePHP(tm) v 1.2.0.4206
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
@@ -53,22 +48,22 @@ function setUp() {
'test' => 'info',
'Message' => array(
'flash' => array(
'layout' => 'default',
'element' => 'default',
'params' => array(),
'message' => 'This is a calling'
),
'notification' => array(
'layout' => 'session_helper',
'element' => 'session_helper',
'params' => array('title' => 'Notice!', 'name' => 'Alert!'),
'message' => 'This is a test of the emergency broadcasting system',
),
'classy' => array(
'layout' => 'default',
'element' => 'default',
'params' => array('class' => 'positive'),
'message' => 'Recorded'
),
'bare' => array(
'layout' => null,
'element' => null,
'message' => 'Bare message',
'params' => array(),
),
@@ -121,7 +116,7 @@ function testRead() {
function testCheck() {
$this->assertTrue($this->Session->check('test'));
$this->assertTrue($this->Session->check('Message.flash.layout'));
$this->assertTrue($this->Session->check('Message.flash.element'));
$this->assertFalse($this->Session->check('Does.not.exist'));
@@ -1,5 +1,5 @@
<div id="notificationLayout">
<h1><?php echo $name; ?></h1>
<h3><?php echo $title; ?></h3>
<p><?php echo $content_for_layout; ?></p>
<p><?php echo $message; ?></p>
</div>

0 comments on commit 4d458e9

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