@@ -346,7 +346,8 @@ cookie by using native PHP sessions.
346
346
347
347
348
348
.. versionadded :: 3.3
349
- The ability to request a ``Session `` in actions was introduced in Symfony 3.3.
349
+ The ability to request a ``Session `` instance in controllers was introduced
350
+ in Symfony 3.3.
350
351
351
352
To retrieve the session, add the :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ SessionInterface `
352
353
type-hint to your argument and Symfony will provide you with a session::
@@ -372,18 +373,6 @@ Stored attributes remain in the session for the remainder of that user's session
372
373
Every ``SessionInterface `` implementation is supported. If you have your
373
374
own implementation, type-hint this in the arguments instead.
374
375
375
- As a developer, you might prefer not to extend the ``Controller ``. To use the
376
- flash message functionality, you can request the flash bag from the
377
- :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ Session `::
378
-
379
- use Symfony\Component\HttpFoundation\Session\Session;
380
-
381
- public function indexAction(Session $session)
382
- {
383
- // getFlashBag is not available in the SessionInterface and requires the Session
384
- $flashBag = $session->getFlashBag();
385
- }
386
-
387
376
.. index ::
388
377
single: Session; Flash messages
389
378
@@ -418,6 +407,20 @@ For example, imagine you're processing a :doc:`form </forms>` submission::
418
407
return $this->render(...);
419
408
}
420
409
410
+ .. tip ::
411
+
412
+ As a developer, you might prefer not to extend the ``Controller ``. To
413
+ use the flash message functionality, you can request the flash bag from
414
+ the :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ Session `::
415
+
416
+ use Symfony\Component\HttpFoundation\Session\Session;
417
+
418
+ public function indexAction(Session $session)
419
+ {
420
+ // getFlashBag is not available in the SessionInterface and requires the Session
421
+ $flashBag = $session->getFlashBag();
422
+ }
423
+
421
424
After processing the request, the controller sets a flash message in the session
422
425
and then redirects. The message key (``notice `` in this example) can be anything:
423
426
you'll use this key to retrieve the message.
0 commit comments