Welcome to the Cookbook

loading...

5.7.1 Methods

Er is geen nog vertaling vertaling voor deze rubriek. Help ons en vertaal dit.. Meer informatie over vertalingen

The Session component is used to interact with session information. It includes basic CRUD functions as well as features for creating feedback messages to users.

It should be noted that Array structures can be created in the Session by using dot notation. So User.username would reference the following:

	array('User' => 
			array('username' => 'clarkKent@dailyplanet.com')
	);
  1. array('User' =>
  2. array('username' => 'clarkKent@dailyplanet.com')
  3. );

Dots are used to indicate nested arrays. This notation is used for all Session component methods wherever a $name is used.

5.7.1.1 write

Er is geen nog vertaling vertaling voor deze rubriek. Help ons en vertaal dit.. Meer informatie over vertalingen

write($name, $value)

Write to the Session puts $value into $name. $name can be a dot separated array. For example:

$this->Session->write('Person.eyeColor', 'Green');
  1. $this->Session->write('Person.eyeColor', 'Green');

This writes the value 'Green' to the session under Person => eyeColor.

5.7.1.2 setFlash

Er is geen nog vertaling vertaling voor deze rubriek. Help ons en vertaal dit.. Meer informatie over vertalingen

setFlash($message, $layout = 'default', $params = array(), $key = 'flash')

Used to set a session variable that can be used for output in the View. $layout allows you to control which layout (located in /app/views/layouts) should be used to render the message in. If you leave the $layout set to 'default', the message will be wrapped with the following:

<div id="flashMessage" class="message"> [message] </div>
  1. <div id="flashMessage" class="message"> [message] </div>
$params allows you to pass additional view variables to the rendered layout. $key sets the $messages index in the Message array. Default is 'flash'.

Parameters can be passed affecting the rendered div, for example padding "class" in the $params array will apply a class to the div output using $session->flash() in your layout or view.

$this->Session->setFlash('Example message text', 'default', array('class' => 'example_class'))
  1. $this->Session->setFlash('Example message text', 'default', array('class' => 'example_class'))

The output from using $session->flash() with the above example would be:

<div id="flashMessage" class="example_class">Example message text</div>
  1. <div id="flashMessage" class="example_class">Example message text</div>

5.7.1.3 read

Er is geen nog vertaling vertaling voor deze rubriek. Help ons en vertaal dit.. Meer informatie over vertalingen

read($name)

Returns the value at $name in the Session. If $name is null the entire session will be returned. E.g.

$green = $this->Session->read('Person.eyeColor');
  1. $green = $this->Session->read('Person.eyeColor');

Retrieve the value Green from the session.

5.7.1.4 check

Er is geen nog vertaling vertaling voor deze rubriek. Help ons en vertaal dit.. Meer informatie over vertalingen

check($name)

Used to check if a Session variable has been set. Returns true on existence and false on non-existence.

5.7.1.5 delete

Er is geen nog vertaling vertaling voor deze rubriek. Help ons en vertaal dit.. Meer informatie over vertalingen

delete($name)
del($name)

Clear the session data at $name. del($name) is deprecated from 1.3.

$this->Session->delete('Person.eyeColor');
  1. $this->Session->delete('Person.eyeColor');

Our session data no longer has the value 'Green', or the index eyeColor set. However, Person is still in the Session. To delete the entire Person information from the session use.

$this->Session->delete('Person');
  1. $this->Session->delete('Person');

5.7.1.6 destroy

Er is geen nog vertaling vertaling voor deze rubriek. Help ons en vertaal dit.. Meer informatie over vertalingen

The destroy method will delete the session cookie and all session data stored in the temporary file system. It will then destroy the PHP session and then create a fresh session.

$this->Session->destroy()
  1. $this->Session->destroy()

5.7.1.7 error

Er is geen nog vertaling vertaling voor deze rubriek. Help ons en vertaal dit.. Meer informatie over vertalingen

error()

Used to determine the last error in a session.