Updating SessionHelper::flash() to use elements for custom flash wrapping html instead of layouts.

This commit is contained in:
mark_story 2009-09-01 00:03:56 -04:00
parent 17e81ab346
commit 4d458e93b6
3 changed files with 15 additions and 26 deletions

View file

@ -1,8 +1,6 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* Short description for file. * Session Helper provides access to the Session in the Views.
* *
* Long description for file * Long description for file
* *
@ -15,14 +13,11 @@
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @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 * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake * @package cake
* @subpackage cake.cake.libs.view.helpers * @subpackage cake.cake.libs.view.helpers
* @since CakePHP(tm) v 1.1.7.3328 * @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 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
if (!class_exists('cakesession')) { if (!class_exists('cakesession')) {
@ -139,21 +134,20 @@ class SessionHelper extends CakeSession {
if (parent::check('Message.' . $key)) { if (parent::check('Message.' . $key)) {
$flash = parent::read('Message.' . $key); $flash = parent::read('Message.' . $key);
if ($flash['layout'] == 'default') { if ($flash['element'] == 'default') {
if (!empty($flash['params']['class'])) { if (!empty($flash['params']['class'])) {
$class = $flash['params']['class']; $class = $flash['params']['class'];
} else { } else {
$class = 'message'; $class = 'message';
} }
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>'; $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']; $out = $flash['message'];
} else { } else {
$view =& ClassRegistry::getObject('view'); $view =& ClassRegistry::getObject('view');
list($tmpVars, $tmpTitle) = array($view->viewVars, $view->pageTitle); $tmpVars = $flash['params'];
list($view->viewVars, $view->pageTitle) = array($flash['params'], ''); $tmpVars['message'] = $flash['message'];
$out = $view->renderLayout($flash['message'], $flash['layout']); $out = $view->element($flash['element'], $tmpVars);
list($view->viewVars, $view->pageTitle) = array($tmpVars, $tmpTitle);
} }
echo($out); echo($out);
parent::del('Message.' . $key); parent::del('Message.' . $key);

View file

@ -1,6 +1,4 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* SessionHelperTest file * SessionHelperTest file
* *
@ -9,20 +7,17 @@
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite> * 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 * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @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 * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake * @package cake
* @subpackage cake.tests.cases.libs.view.helpers * @subpackage cake.tests.cases.libs.view.helpers
* @since CakePHP(tm) v 1.2.0.4206 * @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 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
@ -53,22 +48,22 @@ class SessionHelperTest extends CakeTestCase {
'test' => 'info', 'test' => 'info',
'Message' => array( 'Message' => array(
'flash' => array( 'flash' => array(
'layout' => 'default', 'element' => 'default',
'params' => array(), 'params' => array(),
'message' => 'This is a calling' 'message' => 'This is a calling'
), ),
'notification' => array( 'notification' => array(
'layout' => 'session_helper', 'element' => 'session_helper',
'params' => array('title' => 'Notice!', 'name' => 'Alert!'), 'params' => array('title' => 'Notice!', 'name' => 'Alert!'),
'message' => 'This is a test of the emergency broadcasting system', 'message' => 'This is a test of the emergency broadcasting system',
), ),
'classy' => array( 'classy' => array(
'layout' => 'default', 'element' => 'default',
'params' => array('class' => 'positive'), 'params' => array('class' => 'positive'),
'message' => 'Recorded' 'message' => 'Recorded'
), ),
'bare' => array( 'bare' => array(
'layout' => null, 'element' => null,
'message' => 'Bare message', 'message' => 'Bare message',
'params' => array(), 'params' => array(),
), ),
@ -121,7 +116,7 @@ class SessionHelperTest extends CakeTestCase {
function testCheck() { function testCheck() {
$this->assertTrue($this->Session->check('test')); $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')); $this->assertFalse($this->Session->check('Does.not.exist'));

View file

@ -1,5 +1,5 @@
<div id="notificationLayout"> <div id="notificationLayout">
<h1><?php echo $name; ?></h1> <h1><?php echo $name; ?></h1>
<h3><?php echo $title; ?></h3> <h3><?php echo $title; ?></h3>
<p><?php echo $content_for_layout; ?></p> <p><?php echo $message; ?></p>
</div> </div>