• CakePHP
  • Downloads
    • Releases
    • Pear channel
  • Documentation
    • API
      • 2.3 |
      • 2.2 |
      • 1.3 |
      • 1.2 |
      • 1.1
    • Book
      • 2.x |
      • 1.3 |
      • 1.2 |
      • 1.1
  • Community
    • Issues
    • Bakery
    • Plugins & packages
    • Contributors
    • Google Groups
    • Logo
    • Q & A
    • TV (Screencasts)
  • Services
    • Certification
    • Consultation
    • Support
    • Training
API
Version 2.3
  • 1.2
  • 1.3
  • 2.0
  • 2.1
  • 2.2
  • 2.3
  • 2.4
  • Overview
  • Tree
  • Deprecated

Packages

  • app
    • Config
      • Schema
    • Console
      • Command
    • Controller
    • Model
    • View
      • Helper
  • 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
  • PHP

Classes

  • AclComponent
  • AuthComponent
  • CookieComponent
  • EmailComponent
  • PaginatorComponent
  • RequestHandlerComponent
  • SecurityComponent
  • SessionComponent
  • Package
  • Class

Class SessionComponent

The CakePHP SessionComponent provides a way to persist client data between page requests. It acts as a wrapper for the $_SESSION as well as providing convenience methods for several $_SESSION related functions.

Object
Extended by Component
Extended by SessionComponent
Package: Cake\Controller\Component
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Link: http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html
Link: http://book.cakephp.org/2.0/en/development/sessions.html
Located at Cake/Controller/Component/SessionComponent.php

Method summary

public check ( string $name )

Used to check if a session variable is set

public delete ( string $name )

Wrapper for SessionComponent::del();

public destroy ( )

Used to destroy sessions

public error ( )

Used to determine the last error in a session.

public id ( string $id = null )

Get/Set the session id.

public read ( string $name = null )

Used to read a session values for a key or return values for all keys.

public renew ( )

Used to renew a session id

public setFlash ( string $message , string $element = 'default' , array $params = array() , string $key = 'flash' )

Used to set a session variable that can be used to output messages in the view.

public started ( )

Returns a bool, whether or not the session has been started.

public userAgent ( string $userAgent = null )

Get / Set the userAgent

public valid ( )

Used to check for a valid session.

public write ( string $name , string $value = null )

Used to write a value to a session key.

Method Detail

check( ) public

Used to check if a session variable is set

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

Parameters
string $name
the name of the session key you want to check
Returns
boolean
true is session variable is set, false if not
Link
http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#SessionComponent::check

delete( ) public

Wrapper for SessionComponent::del();

In your controller: $this->Session->delete('Controller.sessKey');

Parameters
string $name
the name of the session key you want to delete
Returns
boolean
true is session variable is set and can be deleted, false is variable was not set.
Link
http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#SessionComponent::delete

destroy( ) public

Used to destroy sessions

In your controller: $this->Session->destroy();

Link
http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#SessionComponent::destroy

error( ) public

Used to determine the last error in a session.

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

Returns
string
Last session error

id( ) public

Get/Set the session id.

When fetching the session id, the session will be started if it has not already been started. When setting the session id, the session will not be started.

Parameters
string $id optional null
Id to use (optional)
Returns
string
The current session id.

read( ) public

Used to read a session values for a key or return values for all keys.

In your controller: $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
value from the session vars
Link
http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#SessionComponent::read

renew( ) public

Used to renew a session id

In your controller: $this->Session->renew();

setFlash( ) public

Used to set a session variable that can be used to output messages in the view.

In your controller: $this->Session->setFlash('This has been saved');

Additional params below can be passed to customize the output, or the Message.[key]. You can also set additional parameters when rendering flash messages. See SessionHelper::flash() for more information on how to do that.

Parameters
string $message
Message to be flashed
string $element optional 'default'
Element to wrap flash message in.
array $params optional array()
Parameters to be sent to layout as view variables
string $key optional 'flash'
Message key, default is 'flash'
Link
http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#creating-notification-messages

started( ) public

Returns a bool, whether or not the session has been started.

Returns
boolean
boolean

userAgent( ) public

Get / Set the userAgent

Parameters
string $userAgent optional null
Set the userAgent

valid( ) public

Used to check for a valid session.

In your controller: $this->Session->valid();

Returns
boolean
true is session is valid, false is session is invalid

write( ) public

Used to write a value to a session key.

In your controller: $this->Session->write('Controller.sessKey', 'session value');

Parameters
string $name
The name of the key your are setting in the session. This should be in a Controller.key format for better organizing
string $value optional null
The value you want to store in a session.
Returns
boolean
Success
Link
http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#SessionComponent::write

Methods inherited from Component

__construct(), __get(), beforeRedirect(), beforeRender(), initialize(), shutdown(), startup()

Methods inherited from Object

_mergeVars(), _set(), _stop(), dispatchMethod(), log(), requestAction(), toString()

Properties inherited from Component

$_Collection, $_componentMap, $components, $settings
CakePHP API documentation generated by ApiGen 3.0dev