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

persistent no more works with Phalcon V4?

Hi, SessionBag is created:

$di->setShared('sessionBag',function () {
    return new \Phalcon\Session\Bag('bag');

but $this->persistent->something shows always the same value. No matter which class this is called from.

This work in Phalcon < V4 but not in Phalcon >4

$test = $this->getDi()->get("sessionBag",[get_class($this)]);

I expect an unique session bag for this class. Whats wrong? Has someone the same problem?

Hi rnt-oak :)

mhm, have you tried "getShared" instead of "get"?

$test = $this->getDi()->getShared("sessionBag");

But I don't know what the second parameter should do for you.

If I understand you correctly, you want to create a singleton - one instance that is returned every time you use it in runtime. Source: https://docs.phalcon.io/4.0/en/di#shared-services

But it looks to me that the persistent thing you mentioned is still available: https://docs.phalcon.io/4.0/de-de/session#persistent-data

Did you get any errors?

Greets, Marco

I believe SessionBag is a component that uses the session service. $this->persistent uses an automatically created session bag for each class. So I don't think you need to define sessionBag as a service in the DI.

In any case, when you're defining sessionBag, you're setting the namespace of "bag" on this line:

return new \Phalcon\Session\Bag('bag');

So every time this service is referenced, it'll be using the same namespace. But there's really no need to define a sessionBag service.

Also as a note: Phalcon's session handling uses PHP's built-in session management, so if you ever want to find out exactly what is being stored, you can just output print_r($_SESSION)