Warning: You are browsing the documentation from version 4 to 10 of Pimcore. Please visit https://pimcore.com/docs/platform/ for the latest versions of Pimcore.
Version: Edit on GitHub

Working with Sessions

If you need sessions, please use the native session handling provided by Symfony (configured through the framework.session config). For details see sessions docs.

Pimcore adds the possibility to configure sessions before they are started through SessionConfiguratorInterface registered as service with the pimcore.session.configurator tag. This is useful when you need a custom session bag for your bundle or application.

Sample Session Configurator

namespace TestBundle\Session\Configurator;
use Pimcore\Session\SessionConfiguratorInterface;
use Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class SessionCartConfigurator implements SessionConfiguratorInterface
     * {@inheritdoc}
    public function configure(SessionInterface $session)
        $bag = new NamespacedAttributeBag('_session_cart');

Session Configurator Service Definition

            - { name: pimcore.session.configurator }

Usage of Configured Session, e.g. in Controller

if ($request->hasSession()) {
    $session = $request->getSession();
    /** @var NamespacedAttributeBag $bag */
    $bag = $session->getBag('session_cart');
    $bag->set('foo', 1);

Symfony framework session is configured by default, so you don't need to configure the session in your config.yaml.

Admin sessions Pimcore\Tool\Session::getReadonly() returns an AttributeBagInterface.