We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Set Session Array in Phalcon 2

Hey Guys,

I just upgraded my Project from Phalcon 1.3.2 to Phalcon 2 (Got a new Server so why use old stuff? :D)

Everything works fine, except my Session.

I set my session like this:

$this->session->set('data', array(
    'time' => time(),
    'plz' => $planet->getPlz(),
    'design' => $user->getDesign(),
    'alliance' => $user->getAllianceid(),
    'back' => NULL
));

To access one of these I use this:

$this->session->get('data')['time'];

But how can I change my variables?

$this->session->set('data['time']', time()); // ???


98.9k

I didn't know Phalcon allowed to do that in 1.3.x, Phalcon 2 return all values by value and not by reference so this is pretty much an undefined behavior which probably will not be ported to 2.0

Ok. In phalcon 1.3.x I could do it like this:

    $this->session->data['time'] = time();

So I have to rewrite session :(

Yeah I just thought about writing my own function by implementing it into Session.zep

Something like this, don't know if this works:

    public function setArray(array! keys, string value)
    {
        //do some stuff
    }


6.7k

I also have this problem,in 1.3.4 I can change the array value which store in session, but 2.x can't do this.