DotKernel PSR-7 Middleware Applications

Handle sessions

This post refers to DotKernel 1, based on Zend Framework 1.
If you are looking for DotKernel 3 related posts, go here.

Session variables are used to store information for a particular period of time. They are used to carry information from one page to another in a website application. The data stored in the session variable can be accessed by PHP any number of times until the session expires.

In DotKernel, Zend_Session_Namespace() is used to create a session:

$session = new Zend_Session_Namespace($namespaceName);

As Zend Framework suggests, to avoid problems use Zend_Session_Namespace instance instead of $_SESSION.

For each module the session has a different namespace and different period of time. The session settings are declared in resource.xml:


It’s not a specific requirement to start a session in each module. For example the RSS module doesn’t need sessions – it is initialized with NULL.

Session is started in the bootstrap of the application – index.php – and stored using Zend_Registry:

$session = Zend_Registry::get('session');

Wherever you need session, use the get method from Zend_Registry:

$session = Zend_Registry::get('session');

Excepting the usage for login, session is also used to store messages. displayMessage() is a View method used to display messages stored in session. This method uses 2 variables: type and text. The message type can be error, info and warning. The text variable is the message that will be displayed.

Whenever you need to display a message use this code to store it in the session:

$session->message['txt'] = $option->errorMessage->login;
$session->message['type'] = 'error';

As you may have noticed, the message text is taken from the dots/*.xml file.

Note:  There is no need to call the displayMessage method, as it is already called from the IndexController.php

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>