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
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
|
|
|
* 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
|
|
|
|
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view.helpers
|
|
|
|
* @since CakePHP v 1.1.7.3328
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
*/
|
2006-11-25 04:15:08 +00:00
|
|
|
class SessionHelper extends CakeSession {
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function read($name = null) {
|
|
|
|
if ($this->__active === true) {
|
2006-11-25 04:15:08 +00:00
|
|
|
return $this->readSessionVar($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
|
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function check($name) {
|
|
|
|
if ($this->__active === true) {
|
2006-11-25 04:15:08 +00:00
|
|
|
return $this->checkSessionVar($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
|
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function error() {
|
|
|
|
if ($this->__active === true) {
|
2006-11-25 04:15:08 +00:00
|
|
|
return $this->getLastError();
|
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.
|
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function flash($key = 'flash') {
|
|
|
|
if ($this->__active === true) {
|
2006-11-25 04:15:08 +00:00
|
|
|
if ($this->checkSessionVar('Message.' . $key)) {
|
|
|
|
e($this->readSessionVar('Message.' . $key));
|
|
|
|
$this->delSessionVar('Message.' . $key);
|
2006-09-07 20:35:35 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-11-25 04:15:08 +00:00
|
|
|
/**
|
|
|
|
* Used to check is a session is valid in a view
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2006-09-07 20:35:35 +00:00
|
|
|
function valid() {
|
|
|
|
if ($this->__active === true) {
|
2006-11-25 04:15:08 +00:00
|
|
|
return $this->isValid();
|
2006-09-07 20:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|