Skip to content

Commit 3896828

Browse files
committed
Merge branch '4.4'
* 4.4: Mention the getParameter() helper in the configuration article
2 parents d934296 + 2ec3d82 commit 3896828

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

configuration.rst

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -638,8 +638,10 @@ the env files ending in ``.local`` (``.env.local`` and ``.env.<environment>.loca
638638
involving a ``.env.dist`` file. For information about upgrading, see:
639639
:doc:`configuration/dot-env-changes`.
640640

641-
Accessing Configuration Values
642-
------------------------------
641+
.. _configuration-accessing-parameters:
642+
643+
Accessing Configuration Parameters
644+
----------------------------------
643645

644646
Controllers and services can access all the configuration parameters. This
645647
includes both the :ref:`parameters defined by yourself <configuration-parameters>`
@@ -650,9 +652,31 @@ all the parameters that exist in your application:
650652
651653
$ php bin/console debug:container --parameters
652654
653-
Parameters are injected in services as arguments to their constructors.
654-
:doc:`Service autowiring </service_container/autowiring>` doesn't work for
655-
parameters. Instead, inject them explicitly:
655+
In controllers extending from the :ref:`AbstractController <the-base-controller-class-services>`,
656+
use the ``getParameter()`` helper::
657+
658+
// src/Controller/UserController.php
659+
namespace App\Controller;
660+
661+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
662+
663+
class UserController extends AbstractController
664+
{
665+
// ...
666+
667+
public function index()
668+
{
669+
$projectDir = $this->getParameter('kernel.project_dir');
670+
$adminEmail = $this->getParameter('app.admin_email');
671+
672+
// ...
673+
}
674+
}
675+
676+
In services and controllers not extending from ``AbstractController``, inject
677+
the parameters as arguments of their constructors. You must inject them
678+
explicitly because :doc:`service autowiring </service_container/autowiring>`
679+
doesn't work for parameters:
656680

657681
.. configuration-block::
658682

0 commit comments

Comments
 (0)