Hi: I am using the latest version of Zend Framework (1.9.3PL1). I set the following in my .ini
; Bootstrap session resources
resources.session.save_path = APPLICATION_PATH "/../data/sessions"
resources.session.use_only_cookies = true
resources.session.remember_me_seconds = 864000
Next I want to initialize my session in my bootstrapper:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initSession()
{
// What goes here!?
}
}
My question is, what goes in the initSession function? What should it return, if anything?
Furthermore, if i just start a session in there, it does not recognize the .ini configuration (e.g., the save_path is unchanged). However, if you move the start to a controller, the .ini configuration is recognized.
EDIT: A possible solution is:
protected function _initSession()
{
// Based on http://framework.zend.com/issues/browse/ZF-6651
$session = $this->getPluginResource('session');
$session->init();
Zend_Session::start();
}
If you use the resources.session.*
-options in your application configuration you must not have a _initSession()
method in your bootstrap as these method will override the execution of the plugin resource session
(Zend_Application_Resource_Session
). The sole exitance of the resources.session.*
-options in the configuration file will make sure that the session will be initialized according to your options.
Please read Zend_Application, Theory of Operation for a detailed discussion about the so-called resource methods and the resource plugins.
Stefan is quite right, you are overriding the default session resource which makes use of those application options.
If you want to define your own _initSession() method and still access those options use something like:
protected function _initSession()
{
$options = $this->getOptions();
$sessionOptions = array(
'save_path' => $options['resources']['session']['save_path']
);
Zend_Session::setOptions($options);
Zend_Session::start();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With