@@ -320,8 +320,8 @@ a new ``locale`` parameter is added to the ``config/services.yaml`` file).
320320
321321.. seealso ::
322322
323- Read the ` Accessing Configuration Values `_ section of this article to learn
324- about how to use these configuration parameters in services and controllers .
323+ Later in this article you can read how to
324+ ref:` get configuration parameters in controllers and services <configuration-accessing-parameters> ` .
325325
326326.. index ::
327327 single: Environments; Introduction
@@ -642,8 +642,10 @@ the env files ending in ``.local`` (``.env.local`` and ``.env.<environment>.loca
642642 involving a ``.env.dist `` file. For information about upgrading, see:
643643 :doc: `configuration/dot-env-changes `.
644644
645- Accessing Configuration Values
646- ------------------------------
645+ .. _configuration-accessing-parameters :
646+
647+ Accessing Configuration Parameters
648+ ----------------------------------
647649
648650Controllers and services can access all the configuration parameters. This
649651includes both the :ref: `parameters defined by yourself <configuration-parameters >`
@@ -654,9 +656,31 @@ all the parameters that exist in your application:
654656
655657 $ php bin/console debug:container --parameters
656658
657- Parameters are injected in services as arguments to their constructors.
658- :doc: `Service autowiring </service_container/autowiring >` doesn't work for
659- parameters. Instead, inject them explicitly:
659+ In controllers extending from the :ref: `AbstractController <the-base-controller-class-services >`,
660+ use the ``getParameter() `` helper::
661+
662+ // src/Controller/UserController.php
663+ namespace App\Controller;
664+
665+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
666+
667+ class UserController extends AbstractController
668+ {
669+ // ...
670+
671+ public function index()
672+ {
673+ $projectDir = $this->getParameter('kernel.project_dir');
674+ $adminEmail = $this->getParameter('app.admin_email');
675+
676+ // ...
677+ }
678+ }
679+
680+ In services and controllers not extending from ``AbstractController ``, inject
681+ the parameters as arguments of their constructors. You must inject them
682+ explicitly because :doc: `service autowiring </service_container/autowiring >`
683+ doesn't work for parameters:
660684
661685.. configuration-block ::
662686
0 commit comments