@@ -184,8 +184,8 @@ For more information, see the :doc:`Routing chapter </routing>`.
184
184
185
185
.. caution ::
186
186
187
- The ``redirect() `` method does not check its destination in any way. If you
188
- redirect to some URL provided by the end-users, your application may be open
187
+ The ``redirect() `` method does not check its destination in any way. If you
188
+ redirect to some URL provided by the end-users, your application may be open
189
189
to the `unvalidated redirects security vulnerability `_.
190
190
191
191
@@ -344,18 +344,17 @@ Symfony provides a nice session object that you can use to store information
344
344
about the user between requests. By default, Symfony stores the attributes in a
345
345
cookie by using native PHP sessions.
346
346
347
- To retrieve the session, call
348
- :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::getSession `
349
- method on the ``Request `` object. This method returns a
350
- :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ SessionInterface ` with easy
351
- methods for storing and fetching things from the session::
352
347
353
- use Symfony\Component\HttpFoundation\Request;
348
+ .. versionadded :: 3.3
349
+ The ability to request a ``Session `` in actions was introduced in Symfony 3.
354
350
355
- public function indexAction(Request $request)
356
- {
357
- $session = $request->getSession();
351
+ To retrieve the session, add the :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ Session `
352
+ type-hint to your argument and Symfony will provide you with a session::
353
+
354
+ use Symfony\Component\HttpFoundation\Session\Session;
358
355
356
+ public function indexAction(Session $session)
357
+ {
359
358
// store an attribute for reuse during a later user request
360
359
$session->set('foo', 'bar');
361
360
@@ -368,6 +367,11 @@ methods for storing and fetching things from the session::
368
367
369
368
Stored attributes remain in the session for the remainder of that user's session.
370
369
370
+ .. tip ::
371
+
372
+ Every ``SessionInterface `` implementation is supported. If you have your
373
+ own implementation, type-hint this in the arguments instead.
374
+
371
375
.. index ::
372
376
single: Session; Flash messages
373
377
0 commit comments