There is no need to both start the session with Zend_Session and also call "$session = new Zend_Session_Namespace();".

What I suggest is this following: First decide on a sensible name that all your controllers can share, some kind of name that suits the purpose of the data that is being shared.

Then, inside the controllers that need to share the data, something like this:

  class SomeController extends Zend_Controller_Action {

     protected $session = null;

     public function init() {
         $this->session = new Zend_Session_Namespace('SomeSharedName');
     }

     /** ... actions using $session here ... */
  }

This is the entire idea behind the namespaced feature of Zend_Session, so that individual application components can have some sense of security and ownership over a "piece" of the global $_SESSION.

Hope this helps,
Ralph


On 1/29/11 10:52 AM, AmirBehzad Eslami wrote:
Hi,

I'm looking for a ZF-way to share the session among different Controllers.
Before ZF, the famous global $_SESSION was available everywhere, and still is.
But I'm trying to access the session data from ZF's API.

In My bootstrap, I have:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
        protected function _initSession()
        {
                Zend_Session::start();

                $session = new Zend_Session_Namespace();
        }

Now how can i access to the session data in the other Controllers?
How do you handle this in your ZF appliactions?
Please let me know.

Thanks in advance,
-behzad

Reply via email to