SessionBag

I am using the \Phalcon\Session\Bag class as in the example. It seems to work. However, I also found that I do not inject the DI in Bag, nor does this happen magically. So, does Session\Bag use the session component at all? And if I would store my sessions in some N/V store like MemCached, would Session\Bag also store there?



507

It will work, hovewer you need to use DI to load it. You can create a new class, override setters and getters, and register it in DI, or simply

        $myBag = $this->getDI()->get('\Phalcon\Session\Bag', ['myBag']);
        $myBag->set('k', 'v');
        var_dump($myBag->get('k'));

You also can put your classname inside get() instead of "\Phalcon\Session\Bag".

Of cource, if you instantiate a class directly with new , getDI() will be null.