1

I'm writing to see if someone of you guys has encountered this problem before and have a chance to understand why it happened to me.

This is the story.

I developed many ZF applications before Zend Framework v. 1.8, then I've stopped for about 18 months. Now I had to start a new project on which I decided to use Zend Framework again.

On my local server I had the version 1.11.3 installed, so I didn't download the latest release.

Before the use of Zend_Application with the Bootstrap.php file I used to start sessions putting my session options in my config.ini file and then loading them into a Zend_Session instance like this:

config.ini

sessions.name = NAME
sessions.use_only_cookies = 1
sessions.save_path = APPLICATION_PATH "/../tmp/sessions"
sessions.strict = on
sessions.remember_me_seconds = 1800

index.php (into the public webserver directory) before starting the application:

Globals::startSession();

custom Globals class with various useful methods:

    class Globals
    {
            static public function startSession()
            {
            $sessions_conf = self::getConfig()->sessions;
            Zend_Session::setOptions($sessions_conf->toArray(););
            Zend_Session::start();
            }
    }

This has always worked very well, enabling my sessions (used with Zend_Session_Namespace) and storing the session files in the save_path.

With Zend_Application the manual tells to simply store the session options in the application.ini file under the "section" resources and Zend_Session will be configured automatically...

I did it like this:

; SESSIONS
resources.session.name = NAME
resources.session.use_only_cookies = 1
resources.session.save_path = APPLICATION_PATH "/../tmp/sessions"
resources.session.strict = on
resources.session.remember_me_seconds = 1800

It didn't worked. So I tried to use (not at the same time!) the _initSession() and _initForceSession() methods in the Bootstrap.php file, putting them at the beginning of the class and writing into them the code:

$this->bootstrap('session');

But session were never working, data were not stored between http requests and session files were never written into the save_path...

Could anyone, please, let me know if this is a normal behaviour (maybe I have missed something somewhere...)?

Obviously I solved the problem re-implementing my older method (and it works perfectly), but I would like to learn how to use it correctly.

Thanks in advance.

tereško
  • 58,060
  • 25
  • 98
  • 150
Alessandro
  • 71
  • 1
  • 7

2 Answers2

1

This should be a case of turn it on and it works, might have made it to easy.

I think you may have a problem with how you set your options in your application.ini:

; SESSIONS
resources.session.name = NAME
resources.session.name.use_only_cookies = 1
resources.session.name.save_path = APPLICATION_PATH "/../tmp/sessions"
resources.session.name.strict = on
resources.session.name.remember_me_seconds = 1800

according to the reference manual

To set a session configuration option, include the basename (the part of the name after "session.") as a key of an array passed to Zend_Session::setOptions().

with your options set correctly the bootstrap _initSession() should just work.

public function _initSession()
{
Zend_Session::start();
}

P.S. I use Zend_Session_Namespace all the time but rarely deal with a global session.

RockyFord
  • 8,529
  • 1
  • 15
  • 21
  • Thanks for your hints, I'll get a try tomorrow and let you know if I will be able to make it work correctly. – Alessandro May 27 '12 at 19:25
  • Nothing to do, I tried to use a basename after the session. part in my application.ini and set the _initSession() function in my Bootstrap.php, but, as before, no session file is stored in the save_path... I really can't understand why. – Alessandro May 29 '12 at 10:15
  • I did a test now using var_dump(Zend_Session::getOptions()); in my _initSession() in the Bootstrap.php file and it seems that none of my ini options have been set... – Alessandro May 29 '12 at 10:27
  • I've tried to insert the following in the __initSession() bootstrap function: – Alessandro May 29 '12 at 10:37
  • `code` public function _initSession() { //$this->bootstrap('session'); //Globals::startSession(); $options = Globals::getConfig()->resources->session; Zend_Session::setOptions($options->toArray()); //var_dump(Zend_Session::getOptions()); //exit(); Zend_Session::start(); }`code` options are assigned to Zend_Session, but no result... always no files in the save_path. It's really strange, I suppose... – Alessandro May 29 '12 at 10:38
0

In your Bootstrap.php add

public function _initSession()
{
Zend_Session::start();
}

session options can be set in application.ini

Mr Coder
  • 8,169
  • 5
  • 45
  • 74
  • I did use _initSession() as you suggested me, but without results, I think that something is missing, maybe the user RockyFord is right with his suggestions, I'll try tomorrow to implement them. – Alessandro May 27 '12 at 19:27
  • This solution gives me the same result of RockyFord's one, no session files are stored in the specified save_path... – Alessandro May 29 '12 at 10:16