Sessions?

I can't seem to get my head around sessions in phalcon (even though it all seem so simple at first glance).

I do this in my public/index.php:

    $di->setShared('session', function() {
        $session = new Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });

and this in my controller

        $this->session->set( "session_var", "TESTING");

I then var_dump the session in my view:

var_dump( $this->session );

And all I get is:

 object(Phalcon\Session\Adapter\Files)#41 (3) { ["_uniqueId":protected]=> NULL ["_started":protected]=> bool(false) ["_options":protected]=> NULL }

no matter how I try to get stuff into the session.

What am I missing here?



10.8k

Check your php.ini for session.save_path, if its commented out - uncomment.



10.6k
edited Jun '14

Nothing wrong with the savepath. The only thing that seem to change in the object is the #41 in the output above (when i set a value in the session). It seems the object is storing the value somehow. Just not outputting them in a vardump. Which makes it pretty hard to debug stuff.

What happens if you put

$this->session->get('session_var')

in the view - does it output correctly?

The session is iterable as well, so - admittedly a bit more work - but you could do:

foreach($this->session as $name=>$val){ echo "$name => $val<br />"; }


10.6k

Thanks, yes, I figured this out. But was just wondering why it didn't output either the name of the session file or something the like. The #n value changed, but I just can't see what it stores.