开发者

Zend Framework specific module session configuration

I'm trying to get a different session configuration for 2 modules.

In my application ini i have a modules set up like :

resources.modules[] =
resources.frontcontroller.moduleDirectory = APPLICATION_PATH "/modules" 
resources.frontcontroller.throwerrors     = true 
resources.layout.layout                   = "layout"

and for the sessions

resources.session.save_path           = APPLICATION_PATH "/temp/session"
resources.session.use_cookies         = true
resources.session.use_only_cookies    = true
resources.session.gc_maxlifetime      = 3600
resources.session.remember_me_seconds = 3600
resources.session.name                = "sid"
resources.session.gc_probability      = 1


backoffice.resources.session.save_path           = APPLICATION_PATH "/temp/bo/session"
backoffice.resources.session.use_cookies         = true
backoffice.resources.session.use_only_cookies    = true
backoffice.resources.session.gc_maxlifetime      = 3600
backoffice.resources.session.remember_me_seconds = 3600
backoffice.resources.session.name                = "BOsid"
backoffice.resources.session.gc_probability      = 1

but when i go the backoffice module i still have my default configuraton

开发者_如何学JAVA

Any idea what should be the best way to get different sessions for different modules ?

Thanks


I want to advise you another method of config customization for specific modules in ZF: 1. Create for each module config file: /modules/$moduleName/configs/module.ini 2. Add to the root Bootstrap the next code:

protected function _initBootstrap()
{
    $_conf = new Zend_Config_Ini(APPLICATION_PATH . "/modules/" . $this->getModuleName() . "/configs/module.ini", APPLICATION_ENV);
    $this->_options = array_merge($this->_options, $_conf->toArray()); 

}


I finally opted for a controller plug-in.

With some code like

class App_Controller_Plugin_Session extends Zend_Controller_Plugin_Abstract
{


public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$config = Zend_Registry::get('config')->toArray();


if( $this->getRequest()->getModuleName() == 'backoffice'   ) {
  $conf = $config['sessionBackoffice'];
} else {
  $conf = $config['sessionDefault'];
}


Zend_Session::setOptions($conf);
Zend_Session::start();

}
}

The plugin need to be added at first in the registerPlugin stack if you some other plugin that require sessions.

If you have a better solution i'm open.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜