Maybe there is a typo in the docs, because you need to manually assign the DI to the Bag, or build a bag from DI to automatically assign it. Usually the session bags are used by accessing the "persistent" property in classes that extends Phalcon\DI\Injectable:
<?php
class UserController extends Phalcon\Mvc\Controller
{
public function indexAction()
{
// Create a persistent variable "name"
$this->persistent->name = "Laura";
}
public function welcomeAction()
{
if (isset($this->persistent->name))
{
echo "Welcome, ", $this->persistent->name;
}
}
}
Or
$user = new Phalcon\Session\Bag();
$user->setDI($di);
$user->name = "Kimbra Johnson";
$user->age = 22;
Or
$di['user'] = function(){
return new Phalcon\Session\Bag();
}