mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
07e43bb0f8
Conflicts: cake/libs/view/scaffolds/edit.ctp cake/libs/view/scaffolds/form.ctp cake/tests/test_app/plugins/test_plugin/views/tests/scaffold.edit.ctp cake/tests/test_app/plugins/test_plugin/views/tests/scaffold.form.ctp cake/tests/test_app/views/posts/scaffold.edit.ctp cake/tests/test_app/views/posts/scaffold.form.ctp lib/Cake/Error/ErrorHandler.php lib/Cake/Model/Behavior/TranslateBehavior.php lib/Cake/Model/Datasource/CakeSession.php lib/Cake/Routing/Router.php lib/Cake/TestSuite/TestManager.php lib/Cake/View/scaffolds/edit.ctp lib/Cake/tests/cases/console/shells/bake.test.php lib/Cake/tests/cases/libs/cake_log.test.php lib/Cake/tests/cases/libs/cake_request.test.php lib/Cake/tests/cases/libs/view/helpers/number.test.php lib/Cake/tests/test_app/plugins/test_plugin/views/tests/scaffold.edit.ctp lib/Cake/tests/test_app/views/posts/scaffold.edit.ctp
118 lines
3.3 KiB
PHP
118 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Session Helper provides access to the Session in the Views.
|
|
*
|
|
* PHP 5
|
|
*
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
*
|
|
* Licensed under The MIT License
|
|
* Redistributions of files must retain the above copyright notice.
|
|
*
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
* @package cake
|
|
* @subpackage cake.cake.libs.view.helpers
|
|
* @since CakePHP(tm) v 1.1.7.3328
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
*/
|
|
|
|
App::uses('AppHelper', 'View/Helper');
|
|
App::uses('CakeSession', 'Model/Datasource');
|
|
|
|
/**
|
|
* Session Helper.
|
|
*
|
|
* Session reading from the view.
|
|
*
|
|
* @package cake
|
|
* @subpackage cake.cake.libs.view.helpers
|
|
* @link http://book.cakephp.org/view/1465/Session
|
|
*/
|
|
class SessionHelper extends AppHelper {
|
|
|
|
/**
|
|
* Used to read a session values set in a controller for a key or return values for all keys.
|
|
*
|
|
* In your view: `$session->read('Controller.sessKey');`
|
|
* Calling the method without a param will return all session vars
|
|
*
|
|
* @param string $name the name of the session key you want to read
|
|
* @return values from the session vars
|
|
* @link http://book.cakephp.org/view/1466/Methods
|
|
*/
|
|
public function read($name = null) {
|
|
return CakeSession::read($name);
|
|
}
|
|
|
|
/**
|
|
* Used to check is a session key has been set
|
|
*
|
|
* In your view: `$session->check('Controller.sessKey');`
|
|
*
|
|
* @param string $name
|
|
* @return boolean
|
|
* @link http://book.cakephp.org/view/1466/Methods
|
|
*/
|
|
public function check($name) {
|
|
return CakeSession::check($name);
|
|
}
|
|
|
|
/**
|
|
* Returns last error encountered in a session
|
|
*
|
|
* In your view: `$session->error();`
|
|
*
|
|
* @return string last error
|
|
* @link http://book.cakephp.org/view/1466/Methods
|
|
*/
|
|
public function error() {
|
|
return CakeSession::error();
|
|
}
|
|
|
|
/**
|
|
* Used to render the message set in Controller::Session::setFlash()
|
|
*
|
|
* In your view: $session->flash('somekey');
|
|
* Will default to flash if no param is passed
|
|
*
|
|
* @param string $key The [Message.]key you are rendering in the view.
|
|
* @return boolean|string Will return the value if $key is set, or false if not set.
|
|
* @access public
|
|
* @link http://book.cakephp.org/view/1466/Methods
|
|
* @link http://book.cakephp.org/view/1467/flash
|
|
*/
|
|
public function flash($key = 'flash') {
|
|
$out = false;
|
|
|
|
if (CakeSession::check('Message.' . $key)) {
|
|
$flash = CakeSession::read('Message.' . $key);
|
|
|
|
if ($flash['element'] == 'default') {
|
|
$class = 'message';
|
|
if (!empty($flash['params']['class'])) {
|
|
$class = $flash['params']['class'];
|
|
}
|
|
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>';
|
|
} elseif ($flash['element'] == '' || $flash['element'] == null) {
|
|
$out = $flash['message'];
|
|
} else {
|
|
$tmpVars = $flash['params'];
|
|
$tmpVars['message'] = $flash['message'];
|
|
$out = $this->_View->element($flash['element'], $tmpVars);
|
|
}
|
|
CakeSession::delete('Message.' . $key);
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Used to check is a session is valid in a view
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function valid() {
|
|
return CakeSession::valid();
|
|
}
|
|
}
|