app\extensions\helper \ Session

Session Helper

Download |
| Newest | Edit
<?php

namespace app\extensions\helper;

class Session extends \lithium\template\Helper {

	/**
	 * Classes used by this helper.
	 *
	 * @var array Key/value pair of classes.
	 */
	protected $_classes = array('session' => '\lithium\storage\Session');

	/**
	 * Session flash message.
	 *
	 * @param string $key Key of flash message. Defaults to 'message' if not set.
	 * @return string Flash message, or null if not set.
	 */
	public function message($key = null) {
		$class = $this->_classes['session'];
		$key = ($key === null) ? 'message' : $key;

		if ($message = $class::read($key)) {
			$class::delete($key);
			return $message;
		}
		return null;
	}

	/**
	 * Read a value from the session.
	 *
	 * @param string $key The key to be fetched.
	 * @return string The value stored in the session, or null if it does not exist.
	 */
	public function read($key = null) {
		$class = $this->_classes['session'];
		return $class::read($key);
	}
}

?>

Description

This helper allows you to write a message to a session key, and have that key displayed and subsequently deleted.

Details

  • Version: 1
  • Created: 2010-07-23 08:48:13
  • File: app/extensions/helper/Session.php

Maintainers