Skip to content

Commit 12cb0d1

Browse files
committed
minor #8399 Improve service container parameters section (zelazowy)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #8399). Discussion ---------- Improve service container parameters section I've noticed that many young programmers inject the whole container to the service only for fetching parameters, and I think it's because of missing example for using an injected parameter in the service but existing example for doing so in the controller. Commits ------- fbaeccf improve service container parameters section
2 parents 9787e64 + fbaeccf commit 12cb0d1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

service_container.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,20 @@ Actually, once you define a parameter, it can be referenced via the ``%parameter
402402
syntax in *any* other service configuration file - like ``config.yml``. Many parameters
403403
are defined in a :ref:`parameters.yml file <config-parameters-yml>`.
404404

405+
You can then fetch the parameter in the service::
406+
407+
class SiteUpdateManager
408+
{
409+
// ...
410+
411+
private $adminEmail;
412+
413+
public function __construct($adminEmail)
414+
{
415+
$this->adminEmail = $adminEmail;
416+
}
417+
}
418+
405419
You can also fetch parameters directly from the container::
406420

407421
public function newAction()

0 commit comments

Comments
 (0)