diff --git a/docs/plugin_services/session.rst b/docs/plugin_services/session.rst index ac4a8dac..68c58863 100644 --- a/docs/plugin_services/session.rst +++ b/docs/plugin_services/session.rst @@ -11,4 +11,46 @@ Session Please read the :xref:`dev docs contributing guidelines` and :xref:`Contributing to Mautic’s documentation` to get started. -.. vale on \ No newline at end of file +.. vale on + +In Mautic 7, the session is part of the request. Obtain it from the current ``Request`` rather than from a ``session`` service. Inject ``Symfony\Component\HttpFoundation\RequestStack`` and call ``getSession()`` on the current request: + +.. code-block:: php + + requestStack->getSession(); + + // Get all session parameters + $all = $session->all(); + + // Get a specific parameter, using 'mars' as the default + $world = $session->get('helloworld.world', 'mars'); + + // Check whether a parameter exists + if ($session->has('helloworld.world')) { + // Do something. + } + + // Set a session parameter + $session->set('helloworld.world', 'mars'); + + // Remove a session parameter + $session->remove('helloworld.world'); + + // Clear the whole session + $session->clear(); + } + } + +Within a controller action, you can also type-hint ``Symfony\Component\HttpFoundation\Request`` as an argument and call ``$request->getSession()`` directly.