CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.9 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.9
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper
  • None

Classes

  • CacheHelper
  • FlashHelper
  • FormHelper
  • HtmlHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • MootoolsEngineHelper
  • NumberHelper
  • PaginatorHelper
  • PrototypeEngineHelper
  • RssHelper
  • SessionHelper
  • TextHelper
  • TimeHelper

Class SessionHelper

Session Helper.

Session reading from the view.

AppHelper
Extended by SessionHelper
Package: Cake\View\Helper
Link: http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/SessionHelper.php

Method Summary

  • check() public
    Checks if a session key has been set.
  • consume() public
    Reads and deletes a session value for a key.
  • error() public
    Returns last error encountered in a session
  • flash() public deprecated
    Used to render the message set in Controller::Session::setFlash()
  • read() public
    Reads a session value for a key or returns values for all keys.
  • valid() public
    Used to check is a session is valid in a view

Method Detail

check() public ¶

check( string $name )

Checks if a session key has been set.

In your view: $this->Session->check('Controller.sessKey');

Parameters
string $name
Session key to check.
Returns
boolean
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::check

consume() public ¶

consume( string $name )

Reads and deletes a session value for a key.

In your view: $this->Session->consume('Controller.sessKey');

Parameters
string $name
the name of the session key you want to read
Returns
mixed
values from the session vars

error() public ¶

error( )

Returns last error encountered in a session

In your view: $this->Session->error();

Returns
string
last error
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#displaying-notifications-or-flash-messages

flash() public deprecated ¶

flash( string $key = 'flash' , array $attrs = array() )

Used to render the message set in Controller::Session::setFlash()

In your view: $this->Session->flash('somekey'); Will default to flash if no param is passed

You can pass additional information into the flash message generation. This allows you to consolidate all the parameters for a given type of flash message into the view.

echo $this->Session->flash('flash', array('params' => array('class' => 'new-flash')));

The above would generate a flash message with a custom class name. Using $attrs['params'] you can pass additional data into the element rendering that will be made available as local variables when the element is rendered:

echo $this->Session->flash('flash', array('params' => array('name' => $user['User']['name'])));

This would pass the current user's name into the flash message, so you could create personalized messages without the controller needing access to that data.

Lastly you can choose the element that is rendered when creating the flash message. Using custom elements allows you to fully customize how flash messages are generated.

echo $this->Session->flash('flash', array('element' => 'my_custom_element'));

If you want to use an element from a plugin for rendering your flash message you can do that using the plugin param:

echo $this->Session->flash('flash', array(
    'element' => 'my_custom_element',
    'params' => array('plugin' => 'my_plugin')
));
Deprecated
3.0.0 Since 2.7, use FlashHelper::render() instead.
Parameters
string $key optional 'flash'
The [Message.]key you are rendering in the view.
array $attrs optional array()

Additional attributes to use for the creation of this flash message. Supports the 'params', and 'element' keys that are used in the helper.

Returns
string
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::flash

read() public ¶

read( string $name = null )

Reads a session value for a key or returns values for all keys.

In your view: $this->Session->read('Controller.sessKey'); Calling the method without a param will return all session vars

Parameters
string $name optional null
the name of the session key you want to read
Returns
mixed
values from the session vars
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::read

valid() public ¶

valid( )

Used to check is a session is valid in a view

Returns
boolean
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::valid
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs