@@ -417,10 +417,6 @@ front controller - see :ref:`page-creation-environments`).
417
417
You'll want to customize the error page your user sees. To do that, see
418
418
the :doc: `/controller/error_pages ` article.
419
419
420
- .. index ::
421
- single: Controller; The session
422
- single: Session
423
-
424
420
.. _controller-request-argument :
425
421
426
422
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
443
439
:ref: `Keep reading <request-object-info >` for more information about using the
444
440
Request object.
445
441
442
+ .. index ::
443
+ single: Controller; The session
444
+ single: Session
445
+
446
+ .. _session-intro :
447
+
446
448
Managing the Session
447
449
--------------------
448
450
449
451
Symfony provides a nice session object that you can use to store information
450
452
about the user between requests. By default, Symfony stores the token in a
451
453
cookie and writes the attributes to a file by using native PHP sessions.
452
454
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
+
453
497
To retrieve the session, add the :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ SessionInterface `
454
498
type-hint to your argument and Symfony will provide you with a session::
455
499
@@ -474,6 +518,8 @@ Stored attributes remain in the session for the remainder of that user's session
474
518
Every ``SessionInterface `` implementation is supported. If you have your
475
519
own implementation, type-hint this in the arguments instead.
476
520
521
+ For more info, see :doc: `/session `.
522
+
477
523
.. index ::
478
524
single: Session; Flash messages
479
525
0 commit comments