Skip to content

adding more details about sessions, including how to activate #8758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -443,13 +439,61 @@ object. To get it in your controller, just add it as an argument and
:ref:`Keep reading <request-object-info>` for more information about using the
Request object.

.. index::
single: Controller; The session
single: Session

.. _session-intro:

Managing the Session
--------------------

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

<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<!-- ... -->
<framework:session handler-id="null" />
</framework:config>
</container>

.. 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::

Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions session.rst
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -11,3 +19,4 @@ Sessions
session/php_bridge
session/proxy_examples

* :doc:`/doctrine/pdo_session_storage`