@@ -148,6 +148,11 @@ that's available to you with or without the use of the base
148148action is to look in the
149149:class: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller ` class.
150150
151+ ..tip ::
152+ If you know what you're doing, you can alternatively extend
153+ :class: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ AbstractController `. It
154+ has all the same shortcuts, but does not have a ```$this->container `` property.
155+
151156..index ::
152157 single: Controller; Redirecting
153158
@@ -236,12 +241,11 @@ The Symfony templating system and Twig are explained more in the
236241Accessing other Services
237242~~~~~~~~~~~~~~~~~~~~~~~~
238243
239- Symfony comes packed with a lot of useful objects, called *services *. These
240- are used for rendering templates, sending emails, querying the database and
241- any other "work" you can think of. When you install a new bundle, it probably
242- brings in even *more * services.
244+ Symfony comes packed with a lot of useful objects, called:doc: `services </service_container >`.
245+ These are used for rendering templates, sending emails, querying the database and
246+ any other "work" you can think of.
243247
244- When extending the basecontroller class, you can access any Symfony service
248+ When extending the base`` Controller `` class, you can access any Symfony service
245249via the:method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::get `
246250method of the ``Controller `` class. Here are several common services you might
247251need::
@@ -252,6 +256,9 @@ need::
252256
253257 $mailer = $this->get('mailer');
254258
259+ // you can also fetch parameters
260+ $someParameter = $this->getParameter('some_parameter');
261+
255262What other services exist? To list all services, use the ``debug:container ``
256263console command:
257264
@@ -261,14 +268,31 @@ console command:
261268
262269 For more information, see the:doc: `/service_container ` article.
263270
264- ..tip ::
271+ Services as Controller Arguments
272+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273+
274+ You can also tell Symfony to pass your a service as a controller argument by type-hinting
275+ it::
265276
266- To get a:ref: `container configuration parameter <config-parameter-intro >`,
267- use the
268- :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::getParameter `
269- method::
277+ use Psr\Log\LoggerInterface
278+ // ...
279+
280+ /**
281+ * @Route("/lucky/number/{max}")
282+ */
283+ public function numberAction($max, LoggerInterface $logger)
284+ {
285+ $logger->info('We are logging!');
270286
271- $from = $this->getParameter('app.mailer.from');
287+ // ...
288+ }
289+
290+ ..note ::
291+ If this isn't working, make sure your controller is registered as a service,
292+ :ref: `autoconfigured <services-autoconfigure >` and extends either
293+ :class: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller ` or
294+ :class: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ AbstractController `. Or,
295+ you can tag it manually with ``controller.service_arguments ``.
272296
273297..index ::
274298 single: Controller; Managing errors
@@ -407,20 +431,6 @@ For example, imagine you're processing a :doc:`form </forms>` submission::
407431 return $this->render(...);
408432 }
409433
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-
424434After processing the request, the controller sets a flash message in the session
425435and then redirects. The message key (``notice `` in this example) can be anything:
426436you'll use this key to retrieve the message.