mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Updating SessionHelper::flash() to use elements for custom flash wrapping html instead of layouts.
This commit is contained in:
parent
17e81ab346
commit
4d458e93b6
3 changed files with 15 additions and 26 deletions
|
@ -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 @@ class SessionHelper extends CakeSession {
|
|||
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 @@ class SessionHelperTest extends CakeTestCase {
|
|||
'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 @@ class SessionHelperTest extends CakeTestCase {
|
|||
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>
|
Loading…
Add table
Reference in a new issue