diff --git a/controller.rst b/controller.rst index 3418956d9ef..b44b8273672 100644 --- a/controller.rst +++ b/controller.rst @@ -417,10 +417,6 @@ front controller - see :ref:`page-creation-environments`). You'll want to customize the error page your user sees. To do that, see the :doc:`/controller/error_pages` article. -.. index:: - single: Controller; The session - single: Session - .. _controller-request-argument: The Request object as a Controller Argument @@ -443,6 +439,12 @@ object. To get it in your controller, just add it as an argument and :ref:`Keep reading ` for more information about using the Request object. +.. index:: + single: Controller; The session + single: Session + +.. _session-intro: + Managing the Session -------------------- @@ -450,6 +452,48 @@ Symfony provides a nice session object that you can use to store information about the user between requests. By default, Symfony stores the token in a cookie and writes the attributes to a file by using native PHP sessions. +First, enable sessions in your configuration: + +.. configuration-block:: + + .. code-block:: yaml + + # config/packages/framework.yaml + framework: + # ... + + session: + # With this config, PHP's native session handling is used + handler_id: ~ + + .. code-block:: xml + + + + + + + + + + + + .. code-block:: php + + // config/packages/framework.php + $container->loadFromExtension('framework', array( + 'session' => array( + // ... + 'handler_id' => null, + ), + )); + To retrieve the session, add the :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface` type-hint to your argument and Symfony will provide you with a session:: @@ -474,6 +518,8 @@ Stored attributes remain in the session for the remainder of that user's session Every ``SessionInterface`` implementation is supported. If you have your own implementation, type-hint this in the arguments instead. +For more info, see :doc:`/session`. + .. index:: single: Session; Flash messages diff --git a/session.rst b/session.rst index 33fbbc61745..3de4511dd22 100644 --- a/session.rst +++ b/session.rst @@ -1,6 +1,14 @@ Sessions ======== +Symfony provides a nice session object that you can use to store information +about the user between requests. + +To see how to use the session, read :ref:`session-intro`. + +More about Sessions +------------------- + .. toctree:: :maxdepth: 1 @@ -11,3 +19,4 @@ Sessions session/php_bridge session/proxy_examples +* :doc:`/doctrine/pdo_session_storage`