Session Trait

trait SessionTrait

Introduction

SessionTrait is a simple way to let object store relevant data in the session. Specifically used in ATK UI some objects want to memorize data. (see https://github.com/atk4/ui/blob/develop/src/Wizard.php#L12)

You would need 3 things. First make use of session trait:

use \atk4\core\SessionTrait;

next you may memorize any value, which will be stored independently from any other object (even of a same class):

$this->memorize('dsn', $dsn);

Later when you need the value, you can simply recall it:

$dsn = $this->recall('dsn');

Properties

property SessionTrait::$session_key

Internal property to make sure that all session data will be stored in one “container” (array key).

Methods

SessionTrait::startSession($options =[])

Create new session.

SessionTrait::destroySession()

Destroy existing session.

SessionTrait::memorize($key, $value)

Remember data in object-relevant session data.

SessionTrait::learn($key, $default = null)

Similar to memorize, but if value for key exist, will return it.

SessionTrait::recall($key, $default = null)

Returns session data for this object. If not previously set, then $default is returned.

SessionTrait::forget($key = null)

Forget session data for arg $key. If $key is omitted will forget all associated session data.