Skip to content

Commit 748ec0a

Browse files
Correcting details of using constants as parameters
1 parent 6bcbf76 commit 748ec0a

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

components/dependency_injection/parameters.rst

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,19 @@ making the class of a service a parameter:
150150
The percent sign inside a parameter or argument, as part of the string, must
151151
be escaped with another percent sign:
152152

153-
.. configuration-block::
153+
.. configuration-block::
154154

155-
.. code-block:: yaml
155+
.. code-block:: yaml
156156
157-
arguments: ['http://symfony.com/?foo=%%s&bar=%%d']
157+
arguments: ['http://symfony.com/?foo=%%s&bar=%%d']
158158
159-
.. code-block:: xml
159+
.. code-block:: xml
160160
161-
<argument type="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
161+
<argument type="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
162162
163-
.. code-block:: php
163+
.. code-block:: php
164164
165-
->addArgument('http://symfony.com/?foo=%%s&bar=%%d');
165+
->addArgument('http://symfony.com/?foo=%%s&bar=%%d');
166166
167167
Array Parameters
168168
----------------
@@ -228,22 +228,29 @@ The container also has support for setting PHP constants as parameters. To
228228
take advantage of this feature, map the name of your constant to a parameter
229229
key, and define the type as ``constant``.
230230

231-
.. code-block:: xml
231+
.. configuration-block::
232232

233-
<?xml version="1.0" encoding="UTF-8"?>
233+
.. code-block:: xml
234234
235-
<container xmlns="http://symfony.com/schema/dic/services"
236-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
235+
<?xml version="1.0" encoding="UTF-8"?>
237236
238-
<parameters>
239-
<parameter key="global.constant.value" type="constant">GLOBAL_CONSTANT</parameter>
240-
<parameter key="my_class.constant.value" type="constant">My_Class::CONSTANT_NAME</parameter>
241-
</parameters>
242-
</container>
237+
<container xmlns="http://symfony.com/schema/dic/services"
238+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
239+
240+
<parameters>
241+
<parameter key="global.constant.value" type="constant">GLOBAL_CONSTANT</parameter>
242+
<parameter key="my_class.constant.value" type="constant">My_Class::CONSTANT_NAME</parameter>
243+
</parameters>
244+
</container>
245+
246+
.. code-block:: php
247+
248+
$container->setParameter('global.constant.value', GLOBAL_CONSTANT);
249+
$container->setParameter('my_class.constant.value', My_Class::CONSTANT_NAME);
243250
244251
.. note::
245252

246-
This only works for XML configuration. If you're *not* using XML, simply
253+
This does not works for Yaml configuration. If you're using Yaml, you can
247254
import an XML file to take advantage of this functionality:
248255

249256
.. configuration-block::
@@ -253,9 +260,3 @@ key, and define the type as ``constant``.
253260
# app/config/config.yml
254261
imports:
255262
- { resource: parameters.xml }
256-
257-
.. code-block:: php
258-
259-
// app/config/config.php
260-
$loader->import('parameters.xml');
261-

0 commit comments

Comments
 (0)