Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit748ec0a

Browse files
Correcting details of using constants as parameters
1 parent6bcbf76 commit748ec0a

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-
<argumenttype="string">http://symfony.com/?foo=%%s&bar=%%d</argument>
161+
<argumenttype="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-
<containerxmlns="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-
<parameterkey="global.constant.value"type="constant">GLOBAL_CONSTANT</parameter>
240-
<parameterkey="my_class.constant.value"type="constant">My_Class::CONSTANT_NAME</parameter>
241-
</parameters>
242-
</container>
237+
<containerxmlns="http://symfony.com/schema/dic/services"
238+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
239+
240+
<parameters>
241+
<parameterkey="global.constant.value"type="constant">GLOBAL_CONSTANT</parameter>
242+
<parameterkey="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-
Thisonlyworks forXML configuration. If you're*not*usingXML, simply
253+
Thisdoes notworks forYaml configuration. If you're usingYaml, 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)

[8]ページ先頭

©2009-2025 Movatter.jp