8000 feature #9477 Removing warning about bind + controller + scalar value… · symfony/symfony-docs@e6100db · GitHub
[go: up one dir, main page]

Skip to content

Commit e6100db

Browse files
committed
feature #9477 Removing warning about bind + controller + scalar values (weaverryan)
This PR was squashed before being merged into the master branch (closes #9477). Discussion ---------- Removing warning about bind + controller + scalar values Docs for symfony/symfony#26658 :) Commits ------- af00dbc adding version note about scalar bind args 4312518 Removing warning about bind + controller + scalar values
2 parents 696a30a + af00dbc commit e6100db

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

controller.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ the argument by its name:
241241
bind:
242242
# for any $logger argument, pass this specific service
243243
$logger: '@monolog.logger.doctrine'
244+
# for any $projectDir argument, pass this parameter value
245+
$projectDir: '%kernel.project_dir%'
244246
245247
.. code-block:: xml
246248
@@ -260,6 +262,7 @@ the argument by its name:
260262
type="service"
261263
id="monolog.logger.doctrine"
262264
/>
265+
<bind key="$projectDir">%kernel.project_dir%</bind>
263266
</service>
264267
</services>
265268
</container>
@@ -274,19 +277,16 @@ the argument by its name:
274277
->setPublic(true)
275278
->setBindings(array(
276279
'$logger' => new Reference('monolog.logger.doctrine'),
280+
'$projectDir' => '%kernel.project_dir%'
277281
))
278282
;
279283
280284
You can of course also use normal :ref:`constructor injection <services-constructor-injection>`
281285
in your controllers.
282286

283-
.. caution::
284-
285-
You can *only* pass *services* to your controller arguments in this way. It's not
286-
possible, for example, to pass a service parameter as a controller argument,
287-
even by using ``bind``. If you need a parameter, use the ``$this->getParameter('kernel.debug')``
288-
shortcut or pass the value through your controller's ``__construct()`` method
289-
and specify its value with ``bind``.
287+
.. versionadded:: 4.1
288+
The ability to bind scalar values to controller arguments was introduced in
289+
Symfony 4.1. Previously you could only bind services.
290290

291291
For more information about services, see the :doc:`/service_container` article.
292292

0 commit comments

Comments
 (0)
0