Session Helper.
Session reading from the view.
check( string $name )
Checks if a session key has been set.
In your view: $this->Session->check('Controller.sessKey');
$name
consume( string $name )
Reads and deletes a session value for a key.
In your view: $this->Session->consume('Controller.sessKey');
$name
error( )
Returns last error encountered in a session
In your view: $this->Session->error();
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') ));
$key
optional 'flash' $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.
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
$name
optional null valid( )
Used to check is a session is valid in a view
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.9/class-SessionHelper.html