Skip to content

Commit 349f3e3

Browse files
committed
adding more details about sessions, including how to activate
1 parent c4707d1 commit 349f3e3

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

controller.rst

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,6 @@ front controller - see :ref:`page-creation-environments`).
417417
You'll want to customize the error page your user sees. To do that, see
418418
the :doc:`/controller/error_pages` article.
419419

420-
.. index::
421-
single: Controller; The session
422-
single: Session
423-
424420
.. _controller-request-argument:
425421

426422
The Request object as a Controller Argument
@@ -443,13 +439,61 @@ object. To get it in your controller, just add it as an argument and
443439
:ref:`Keep reading <request-object-info>` for more information about using the
444440
Request object.
445441

442+
.. index::
443+
single: Controller; The session
444+
single: Session
445+
446+
.. _session-intro:
447+
446448
Managing the Session
447449
--------------------
448450

449451
Symfony provides a nice session object that you can use to store information
450452
about the user between requests. By default, Symfony stores the token in a
451453
cookie and writes the attributes to a file by using native PHP sessions.
452454

455+
First, enable sessions in your configuration:
456+
457+
.. configuration-block::
458+
459+
.. code-block:: diff
460+
461+
# config/packages/framework.yaml
462+
framework:
463+
# ...
464+
465+
+ session:
466+
+ # With this config, PHP's native session handling is used
467+
+ handler_id: ~
468+
469+
.. code-block:: xml
470+
471+
<!-- config/packages/framework.xml -->
472+
<?xml version="1.0" encoding="UTF-8" ?>
473+
<container xmlns="http://symfony.com/schema/dic/services"
474+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
475+
xmlns:framework="http://symfony.com/schema/dic/symfony"
476+
xsi:schemaLocation="http://symfony.com/schema/dic/services
477+
http://symfony.com/schema/dic/services/services-1.0.xsd
478+
http://symfony.com/schema/dic/symfony
479+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
480+
481+
<framework:config>
482+
<!-- ... -->
483+
<framework:session handler-id="null" />
484+
</framework:config>
485+
</container>
486+
487+
.. code-block:: php
488+
489+
// config/packages/framework.php
490+
$container->loadFromExtension('framework', array(
491+
'session' => array(
492+
// ...
493+
'handler_id' => null,
494+
),
495+
));
496+
453497
To retrieve the session, add the :class:`Symfony\\Component\\HttpFoundation\\Session\\SessionInterface`
454498
type-hint to your argument and Symfony will provide you with a session::
455499

@@ -474,6 +518,8 @@ Stored attributes remain in the session for the remainder of that user's session
474518
Every ``SessionInterface`` implementation is supported. If you have your
475519
own implementation, type-hint this in the arguments instead.
476520

521+
For more info, see :doc:`/session`.
522+
477523
.. index::
478524
single: Session; Flash messages
479525

session.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Sessions
22
========
33

4+
Symfony provides a nice session object that you can use to store information
5+
about the user between requests.
6+
7+
To see how to use the session, read :ref:`session-intro`.
8+
9+
More about Sessions
10+
-------------------
11+
412
.. toctree::
513
:maxdepth: 1
614

@@ -11,3 +19,4 @@ Sessions
1119
session/php_bridge
1220
session/proxy_examples
1321

22+
* :doc:`/doctrine/pdo_session_storage`

0 commit comments

Comments
 (0)