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.
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
booleantrue is session variable is set, false if not
Link
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
booleantrue is session variable is set and can be deleted, false is variable was not set.
Link
error( ) public
Used to determine the last error in a session.
In your controller: $this->Session->error();
Returns
stringLast 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
stringThe 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
mixedvalue from the session vars
Link
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
started( ) public
Returns a bool, whether or not the session has been started.
Returns
booleanboolean
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
booleantrue 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
booleanSuccess
Link
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
|