@@ -346,7 +346,8 @@ cookie by using native PHP sessions.
346346
347347
348348.. 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.
350351
351352To retrieve the session, add the :class: `Symfony\\ Component\\ HttpFoundation\\ Session\\ SessionInterface `
352353type-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
372373 Every ``SessionInterface `` implementation is supported. If you have your
373374 own implementation, type-hint this in the arguments instead.
374375
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-
387376.. index ::
388377 single: Session; Flash messages
389378
@@ -418,6 +407,20 @@ For example, imagine you're processing a :doc:`form </forms>` submission::
418407 return $this->render(...);
419408 }
420409
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+
421424After processing the request, the controller sets a flash message in the session
422425and then redirects. The message key (``notice `` in this example) can be anything:
423426you'll use this key to retrieve the message.
0 commit comments