On 26 May 2008, at 08:29, Matthew Weier O'Phinney wrote:

-- bfoust <[EMAIL PROTECTED]> wrote
(on Monday, 26 May 2008, 12:40 AM -0700):
Is there any way to just make $site_sess global to all models and
controllers


You could create MyView and MyController subclasses that automatically instantiate the Zend_Session_Namespace in their constructor and assign it to
$this->session.

This would be better done via an action helper; please read my tutorial
on action helpers:

   http://devzone.zend.com/article/3350-Action-Helpers-in-Zend-Framework

I may be (and probably am) missing something here about the usefulness of making a session action helper, but that's probably because I already subclass the action controller so I was able to do something like this pretty easily in my extended controller class (abbreviated code):

public function __construct()
{
    Zend_Session::start();
    $this->session = new Zend_Session_Namespace('My_Session');
}

This would allow me to easily use something like $this->session->hello = 'World' throughout my controllers.

If I understand this discussion correctly, creating a session helper would involve something like this:

class My_Action_Helper_Session extends Zend_Controller_Action_Helper_Abstract
{
    /**
     * @var Zend_Loader_PluginLoader
     */
    public $pluginLoader;

    /**
     * Constructor: initialize plugin loader
     *
     * @return void
     */
    public function __construct()
    {
        $this->pluginLoader = new Zend_Loader_PluginLoader();
    }

    public function init()
    {
        Zend_Session::start();
        return new Zend_Session_Namespace('My_Session');
    }
}

This then means that to set a session variable in my controller, I would need to do something like $this->_helper->session->hello = 'World', correct? Alternatively, in my controller constructor, I could do something like this:

public function __construct()
{
    $this->session = $this->_helper->session;
}

While I'm not opposed to it, this seems like more abstraction (and typing) than is necessary for basic session functionality that's global to all controllers. Aside from the ability to do stuff like preDispatch, postDispatch, etc., am I missing something?

Thanks,

-f-


--
Derek Fong
Web Application Developer
subtitle designs inc. <http://www.subtitled.com/>

"Mistakes are the portals of discovery." --James Joyce
    >> GPG key/fingerprint available upon request <<

Reply via email to