Leafiny Documentation
Session
This section describes Leafiny session management.
Context
A session context is a data storage in the session that can contain arbitrary data.
The default frontend context is named frontend, and the admin context is named backend.
Initialization
The frontend session is initialized in the Frontend module, with an observer:
/** modules/Frontend/etc/config.php **/
'events' => [
'frontend_page_pre_process' => [
/* ... */
'frontend_page_init_session' => 200,
],
],
'observer' => [
/* ... */
'frontend_page_init_session' => [
'class' => Frontend_Observer_InitSession::class,
],
],
If you do not need a session (static site, single page…), delete this observer.
Store data
Add data
$session = App::getSession(Core_Template_Abstract::CONTEXT_DEFAULT); // frontend
if ($session) {
$session->set('key', $data);
}
Retrieve data
$session = App::getSession(Core_Template_Abstract::CONTEXT_DEFAULT); // frontend
if ($session) {
$data = $session->get('key');
}
Delete data
$session = App::getSession(Core_Template_Abstract::CONTEXT_DEFAULT); // frontend
if ($session) {
$session->destroy('key');
}