2006-09-07 20:35:35 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-09-07 20:35:35 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-09-07 20:35:35 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view.helpers
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 1.1.7.3328
|
2006-09-07 20:35:35 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*/
|
|
|
|
/**
|
2006-11-25 04:15:08 +00:00
|
|
|
* Session Helper.
|
2006-09-07 20:35:35 +00:00
|
|
|
*
|
2006-11-25 04:15:08 +00:00
|
|
|
* Session reading from the view.
|
2006-09-07 20:35:35 +00:00
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view.helpers
|
|
|
|
*
|
|
|
|
*/
|
2007-08-25 18:00:19 +00:00
|
|
|
if(!class_exists('cakesession')) {
|
|
|
|
uses('session');
|
|
|
|
}
|
2006-11-25 04:15:08 +00:00
|
|
|
class SessionHelper extends CakeSession {
|
2006-11-25 08:55:16 +00:00
|
|
|
/**
|
|
|
|
* List of helpers used by this helper
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $helpers = null;
|
2006-11-25 04:15:08 +00:00
|
|
|
/**
|
|
|
|
* Used to determine if methods implementation is used, or bypassed
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
var $__active = true;
|
|
|
|
/**
|
2006-11-25 04:15:08 +00:00
|
|
|
* Class constructor
|
2006-09-07 20:35:35 +00:00
|
|
|
*
|
2006-11-25 04:15:08 +00:00
|
|
|
* @param string $base
|
2006-09-07 20:35:35 +00:00
|
|
|
*/
|
|
|
|
function __construct($base = null) {
|
2006-11-25 08:43:17 +00:00
|
|
|
if (!defined('AUTO_SESSION') || AUTO_SESSION === true) {
|
2006-11-25 04:15:08 +00:00
|
|
|
parent::__construct($base, false);
|
2006-09-07 20:35:35 +00:00
|
|
|
} else {
|
|
|
|
$this->__active = false;
|
|
|
|
}
|
|
|
|
}
|
2007-04-04 07:25:48 +00:00
|
|
|
/**
|
|
|
|
* Turn sessions on if AUTO_SESSION is set to false in core.php
|
|
|
|
*
|
|
|
|
* @param string $base
|
|
|
|
*/
|
|
|
|
function activate($base = null) {
|
|
|
|
$this->__active = true;
|
|
|
|
}
|
2006-11-25 04:15:08 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2007-04-04 07:25:48 +00:00
|
|
|
* @access public
|
2006-11-25 04:15:08 +00:00
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function read($name = null) {
|
|
|
|
if ($this->__active === true) {
|
2007-02-12 21:46:17 +00:00
|
|
|
return parent::read($name);
|
2006-09-07 20:35:35 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-25 04:15:08 +00:00
|
|
|
/**
|
|
|
|
* Used to check is a session key has been set
|
|
|
|
*
|
|
|
|
* In your view: $session->check('Controller.sessKey');
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return boolean
|
2007-04-04 07:25:48 +00:00
|
|
|
* @access public
|
2006-11-25 04:15:08 +00:00
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function check($name) {
|
|
|
|
if ($this->__active === true) {
|
2007-02-12 21:46:17 +00:00
|
|
|
return parent::check($name);
|
2006-09-07 20:35:35 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-25 04:15:08 +00:00
|
|
|
/**
|
|
|
|
* Returns last error encountered in a session
|
|
|
|
*
|
|
|
|
* In your view: $session->error();
|
|
|
|
*
|
|
|
|
* @return string last error
|
2007-04-04 07:25:48 +00:00
|
|
|
* @access public
|
2006-11-25 04:15:08 +00:00
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function error() {
|
|
|
|
if ($this->__active === true) {
|
2007-02-12 22:29:49 +00:00
|
|
|
return parent::error();
|
2006-09-07 20:35:35 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-25 04:15:08 +00:00
|
|
|
/**
|
|
|
|
* 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 string Will echo the value if $key is set, or false if not set.
|
2007-04-04 07:25:48 +00:00
|
|
|
* @access public
|
2006-11-25 04:15:08 +00:00
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function flash($key = 'flash') {
|
|
|
|
if ($this->__active === true) {
|
2007-02-12 21:46:17 +00:00
|
|
|
if (parent::check('Message.' . $key)) {
|
2007-03-31 19:37:59 +00:00
|
|
|
$flash = parent::read('Message.' . $key);
|
|
|
|
|
|
|
|
if ($flash['layout'] == 'default') {
|
|
|
|
$out = '<div id="' . $key . 'Message" class="message">' . $flash['message'] . '</div>';
|
|
|
|
} elseif ($flash['layout'] == '' || $flash['layout'] == null) {
|
|
|
|
$out = $flash['message'];
|
|
|
|
} else {
|
|
|
|
$view =& ClassRegistry::getObject('view');
|
|
|
|
list($tmpLayout, $tmpVars, $tmpTitle) = array($view->layout, $view->viewVars, $view->pageTitle);
|
|
|
|
list($view->layout, $view->viewVars, $view->pageTitle) = array($flash['layout'], $flash['params'], '');
|
|
|
|
$out = $view->renderLayout($flash['message']);
|
|
|
|
list($view->layout, $view->viewVars, $view->pageTitle) = array($tmpLayout, $tmpVars, $tmpTitle);
|
|
|
|
}
|
|
|
|
e($out);
|
2007-02-12 21:46:17 +00:00
|
|
|
parent::del('Message.' . $key);
|
2007-03-29 13:43:06 +00:00
|
|
|
return true;
|
2006-09-07 20:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-11-25 04:15:08 +00:00
|
|
|
/**
|
|
|
|
* Used to check is a session is valid in a view
|
|
|
|
*
|
|
|
|
* @return boolean
|
2007-04-04 07:25:48 +00:00
|
|
|
* @access public
|
2006-11-25 04:15:08 +00:00
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function valid() {
|
|
|
|
if ($this->__active === true) {
|
2007-03-31 19:37:59 +00:00
|
|
|
return parent::valid();
|
2006-09-07 20:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 19:05:31 +00:00
|
|
|
/**
|
|
|
|
* Override CakeSession::write().
|
|
|
|
* This method should not be used in a view
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function write() {
|
|
|
|
trigger_error(__('You can not write to a Session from the view', true), E_USER_WARNING);
|
|
|
|
}
|
2006-09-07 20:35:35 +00:00
|
|
|
}
|
|
|
|
?>
|