Today I have tried with Session in Zend Framework. Actually Session handling is very simple in Zend Framework. It’s handled very efficiently using Object Oriented Programming. In this article I’m going to discuss some useful techniques of using Zend Framework Session and Session namespace. In Zend framework, you can use both Zend_Session and Zend_Session_Namespace which extends abstract class Zend_Session_Abstract. So these two inherited methods are available in Zend_Session_Abstract automatically.
You can find all functions related to session handling at Zend/Session/Abstract.php. You can use either Zend_Session or Zend_Session_Namespace class object, but I would recommend Zend_Session_Namespace class object which is more efficient. You can instantiate session using Zend_Session_Namespace class object as below:
The argument for namespace is optional, but it’s better to pass it. if you don’t pass it, Zend Session Namespace will assign its name a string “default”.
To store values in session variable, you will need to do the following.
Below is the example code to retrieve values from session.
- $yoursession = new Zend_Session_Namespace(’Namespace’);
- $fruits = $yoursession->fruits;
If you want to go deep, you can get many useful functions in Zend_Session_Abstract.php, Zend_Session_Nampspace.php, and Zend_Session.php.