October 26, 2012

October 26, 2012
2
In this article we are going to discuss about how to reading and writing the session data using the Zend Session Namespace in Zend Framework. Also discuss about some useful techniques of 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. In Zend/Session/Abstract.php file, you can find all functions related to session handling.

$mysession = new Zend_Session_Namespace(’Namespace’);

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.

$mysession->fruits = ‘Apple’;

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.

2 comments:

  1. Thanks for an insightful post. These comments are really helpful.. I found a lot of useful tips from this post
    zend framework development

    ReplyDelete