0

I am very new to this Zend_Session thing. I do have a Zend Framework App running; now I want to add some "features" to it. One of that features requires some data contained in a Session, so it is stored over all sites, the user will visit.

In my Bootstrap, I have

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initSession() {
        Zend_Session::setOptions(array(
          'use_only_cookies' => 'on',
          'remember_me_seconds' => 864000
        ));
        Zend_Session::start();
    }
}

In my model, there is a function that stores data into the $_SESSION for a given keyword:

 $_SESSION['foo'][urlencode($keyword)] = array(   
              'data' => $base->some->foo[0]->fish->data         
            );

The new data is only set to session, if the session-key (with the keyword) is not set. I checked that with zend debugger, all is running well.

Now, when I call the page first, all's running well. When I reload the page (or move to another), the values in the Session are gone. So, to be exact, the keys are there, the $_SESSION Array is (for example) 20 entries of size. There is an entry, but it is null.

$_SESSION['foo']['my+foo']['data'] = null

When I call:

Zend_Debug::dump($_SESSION['foo']['my+foo']);

I get:

array (size=1)
  'data' => null

So, it is there and it had killed my value.

What is the magic voodoo to get it running like when I use a simple session_start()?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Paladin
  • 1,637
  • 13
  • 28
  • Why don't you use Zend_Session? Zend Session has not so simple inner structure and may just remove your data while saving own info. – Viktor S. Sep 04 '12 at 20:37
  • 1
    Is this SimpleXML data you are trying to save to the session? If so, try casting to a string when you insert it into the session: `$_SESSION['foo'][urlencode($keyword)] = array( 'data' => (string)$base->some->foo[0]->fish->data );` – drew010 Sep 04 '12 at 21:31
  • Best guess is that you are overwriting your data somewhere in the request loop and are not aware of it(I've done it to and it can be hard to find). Check out [Zend_Session_Namespace](http://framework.zend.com/manual/en/zend.session.basic_usage.html) – RockyFord Sep 05 '12 at 01:54
  • Sorry, no change. Have tried with Zend_Session and simple session_start() stuff, all same. Tried to store the simplexml data the way above, no change. And: Its a very very simple ZF project, i do nothing in my request loop, that is not part of the standard (i even do not know how to change it, even i want so ;)). why my session data get null ? – Paladin Sep 05 '12 at 07:05
  • So, i got it, i have to convert every single value from the simplexml object to its representation to my session, then it will be saved ... okay, thanks for bringing me on the right way, drew010, you got it ;) – Paladin Sep 05 '12 at 07:55

2 Answers2

1

Press Ctrl + F and replace everything with the Zend_Session_Namespace object instead of the super global $_SESSION:

$session = new Zend_Session_Namespace('foo');
$session->someData = array(   
    'data' => array('blah') 
);

If the error continues, extends the Zend_Session_Namespace and put an echo (for debug) whenever you change the session data, then you'll be able to know if it's being replaced by another piece of code without your acknowledgement.

Or better, use an interactive debugger and inspect the class line by line (i.e. xDebugger). That one never fails ;)

Keyne Viana
  • 6,194
  • 2
  • 24
  • 55
  • Sorry, that did not change anything. I extended Zend_Session_Namespace, but i get not echo. Seems, data will get lost between two calls. – Paladin Sep 05 '12 at 07:04
  • So, i debugged my project (zend debugger) and as soon, as i call session_start, my $_SESSION object is created, BUT the 'foo' section is filled with the correct keys, but all values are null, example: ['foo']['bar']['data'] is there but its null. another section in the $_SESSION is all right, $_SESSION['what'][0] is there and has correct values ... could it be, that the key-names are too large? – Paladin Sep 05 '12 at 07:30
0

drew010 made it, i have to save every single value to it's representation to my session, so

$_SESSION['foo']['bar'] = array(
 'data' => (int) $base->some->foo[0]->fish->data,
  'moredata' => (string)$base->some->foo[0]->fish->moredata
);

and so on. Thanks!

Paladin
  • 1,637
  • 13
  • 28