@@ -6,8 +6,8 @@ How to Organize Configuration Files
6
6
7
7
The default Symfony2 Standard Edition defines three
8
8
:doc: `execution environments </cookbook/configuration/environments >` called
9
- ``dev ``, ``prod ``, and ``test ``. An environment simply represents a way to
10
- execute the same codebase with different configuration .
9
+ ``dev ``, ``prod `` and ``test ``. An environment simply represents a way to
10
+ execute the same codebase with different configurations .
11
11
12
12
In order to select the configuration file to load for each environment, Symfony
13
13
executes the ``registerContainerConfiguration() `` method of the ``AppKernel ``
@@ -115,14 +115,21 @@ files, including the common files:
115
115
116
116
.. code-block :: xml
117
117
118
- <!-- # app/config/dev/config.xml -->
119
- <imports >
120
- < import resource = " ../common/config.xml " />
121
- < import resource = " parameters.xml " />
122
- < import resource = " security.xml " />
123
- </ imports >
118
+ <!-- app/config/dev/config.xml -->
119
+ <? xml version = " 1.0 " encoding = " UTF-8 " ? >
120
+ < container xmlns = " http://symfony.com/schema/dic/services "
121
+ xmlns : xsi = " http://www.w3.org/2001/XMLSchema-instance "
122
+ xsi : schemaLocation = " http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
123
+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd " >
124
124
125
- <!-- ... -->
125
+ <imports >
126
+ <import resource =" ../common/config.xml" />
127
+ <import resource =" parameters.xml" />
128
+ <import resource =" security.xml" />
129
+ </imports >
130
+
131
+ <!-- ... -->
132
+ </container >
126
133
127
134
.. code-block :: php
128
135
@@ -147,12 +154,21 @@ files, including the common files:
147
154
148
155
.. code-block :: xml
149
156
150
- <!-- # app/config/prod/config.xml -->
151
- <imports >
152
- <import resource =" ../common/config.xml" />
153
- <import resource =" parameters.xml" />
154
- <import resource =" security.xml" />
155
- </imports >
157
+ <!-- app/config/prod/config.xml -->
158
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
159
+ <container xmlns =" http://symfony.com/schema/dic/services"
160
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
161
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
162
+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
163
+
164
+ <imports >
165
+ <import resource =" ../common/config.xml" />
166
+ <import resource =" parameters.xml" />
167
+ <import resource =" security.xml" />
168
+ </imports >
169
+
170
+ <!-- ... -->
171
+ </container >
156
172
157
173
<!-- ... -->
158
174
@@ -178,13 +194,20 @@ files, including the common files:
178
194
179
195
.. code-block :: xml
180
196
181
- <!-- # app/config/config.xml -->
182
- <imports >
183
- <import resource =" parameters.xml" />
184
- <import resource =" security.xml" />
185
- </imports >
197
+ <!-- app/config/config.xml -->
198
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
199
+ <container xmlns =" http://symfony.com/schema/dic/services"
200
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
201
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
202
+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
186
203
187
- <!-- ... -->
204
+ <imports >
205
+ <import resource =" parameters.xml" />
206
+ <import resource =" security.xml" />
207
+ </imports >
208
+
209
+ <!-- ... -->
210
+ </container >
188
211
189
212
.. code-block :: php
190
213
@@ -243,14 +266,15 @@ make Symfony aware of the new file organization::
243
266
}
244
267
245
268
Following the same technique explained in the previous section, make sure to
246
- load the appropriate configuration files from each main file (``common.yml ``,
269
+ import the appropriate configuration files from each main file (``common.yml ``,
247
270
``dev.yml `` and ``prod.yml ``).
248
271
249
- Advanced Tecniques
250
- ------------------
272
+ Advanced Techniques
273
+ -------------------
251
274
252
- Symfony loads configuration files using the ``Config component </components/config> ``,
253
- which provides some advanced features.
275
+ Symfony loads configuration files using the
276
+ ``Config component </components/config/introduction> ``, which provides some
277
+ advanced features.
254
278
255
279
Mix and Match Configuration Formats
256
280
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -273,15 +297,22 @@ format (``.yml``, ``.xml``, ``.php``, ``.ini``):
273
297
274
298
.. code-block :: xml
275
299
276
- <!-- # app/config/config.xml -->
277
- <imports >
278
- <import resource =" parameters.yml" />
279
- <import resource =" services.xml" />
280
- <import resource =" security.yml" />
281
- <import resource =" legacy.php" />
282
- </imports >
300
+ <!-- app/config/config.xml -->
301
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
302
+ <container xmlns =" http://symfony.com/schema/dic/services"
303
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
304
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
305
+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
283
306
284
- <!-- ... -->
307
+ <imports >
308
+ <import resource =" parameters.yml" />
309
+ <import resource =" services.xml" />
310
+ <import resource =" security.yml" />
311
+ <import resource =" legacy.php" />
312
+ </imports >
313
+
314
+ <!-- ... -->
315
+ </container >
285
316
286
317
.. code-block :: php
287
318
@@ -297,8 +328,8 @@ format (``.yml``, ``.xml``, ``.php``, ``.ini``):
297
328
298
329
The ``IniFileLoader `` parses the file contents using the
299
330
:phpfunction: `parse_ini_file ` function, therefore, you can only set
300
- parameters to string values. To set parameters to other data types
301
- (e.g. boolean, integer, etc), the other loaders are recommended .
331
+ parameters to string values. Use one of the other loaders if you want
332
+ to use other data types (e.g. boolean, integer, etc.) .
302
333
303
334
If you use any other configuration format, you have to define your own loader
304
335
class extending it from :class: `Symfony\\ Component\\ DependencyInjection\\ Loader\\ FileLoader `.
@@ -319,20 +350,27 @@ by loading an entire directory:
319
350
320
351
# app/config/config.yml
321
352
imports :
322
- - { resource: 'bundles/' }
323
- - { resource: 'services/' }
353
+ - { resource: 'bundles/' }
354
+ - { resource: 'services/' }
324
355
325
356
# ...
326
357
327
358
.. code-block :: xml
328
359
329
- <!-- # app/config/config.xml -->
330
- <imports >
331
- <import resource =" bundles/" />
332
- <import resource =" services/" />
333
- </imports >
360
+ <!-- app/config/config.xml -->
361
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
362
+ <container xmlns =" http://symfony.com/schema/dic/services"
363
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
364
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
365
+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
334
366
335
- <!-- ... -->
367
+ <imports >
368
+ <import resource =" bundles/" />
369
+ <import resource =" services/" />
370
+ </imports >
371
+
372
+ <!-- ... -->
373
+ </container >
336
374
337
375
.. code-block :: php
338
376
@@ -343,39 +381,46 @@ by loading an entire directory:
343
381
// ...
344
382
345
383
346
- The Config component will look for recursively in the ``bundles/ `` and ``services/ ``
384
+ The Config component will recursively look in the ``bundles/ `` and ``services/ ``
347
385
directories and it will load any supported file format (``.yml ``, ``.xml ``,
348
386
``.php ``, ``.ini ``).
349
387
350
388
Global Configuration Files
351
389
~~~~~~~~~~~~~~~~~~~~~~~~~~
352
390
353
- Some system administrators may prefer to store sensitive parameteres in global
354
- configuration files under the `` /etc `` directory. Imagine that the database
355
- credentials for your website are stored in the ``/etc/sites/mysite.com/parameters.yml ``.
356
- Loading this file is as simple as indicating the full file path when importing
357
- it from any other configuration file:
391
+ Some system administrators may prefer to store sensitive parameters in files
392
+ outside the project directory. Imagine that the database credentials for your
393
+ website are stored in the ``/etc/sites/mysite.com/parameters.yml ``. Loading this
394
+ file is as simple as indicating the full file path when importing it from any
395
+ other configuration file:
358
396
359
397
.. configuration-block ::
360
398
361
399
.. code-block :: yaml
362
400
363
401
# app/config/config.yml
364
402
imports :
365
- - { resource: 'parameters.yml' }
366
- - { resource: '/etc/sites/mysite.com/parameters.yml' }
403
+ - { resource: 'parameters.yml' }
404
+ - { resource: '/etc/sites/mysite.com/parameters.yml' }
367
405
368
406
# ...
369
407
370
408
.. code-block :: xml
371
409
372
- <!-- # app/config/config.xml -->
373
- <imports >
374
- <import resource =" parameters.yml" />
375
- <import resource =" /etc/sites/mysite.com/parameters.yml" />
376
- </imports >
410
+ <!-- app/config/config.xml -->
411
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
412
+ <container xmlns =" http://symfony.com/schema/dic/services"
413
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
414
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
415
+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
377
416
378
- <!-- ... -->
417
+ <imports >
418
+ <import resource =" parameters.yml" />
419
+ <import resource =" /etc/sites/mysite.com/parameters.yml" />
420
+ </imports >
421
+
422
+ <!-- ... -->
423
+ </container >
379
424
380
425
.. code-block :: php
381
426
@@ -385,7 +430,7 @@ it from any other configuration file:
385
430
386
431
// ...
387
432
388
- Most of the time, local developers won't have the same files that exist in the
433
+ Most of the time, local developers won't have the same files that exist on the
389
434
production servers. For that reason, the Config component provides the
390
435
``ignore_errors `` option to silently discard errors when the loaded file
391
436
doesn't exist:
@@ -396,20 +441,27 @@ doesn't exist:
396
441
397
442
# app/config/config.yml
398
443
imports :
399
- - { resource: 'parameters.yml' }
400
- - { resource: '/etc/sites/mysite.com/parameters.yml', ignore_errors: true }
444
+ - { resource: 'parameters.yml' }
445
+ - { resource: '/etc/sites/mysite.com/parameters.yml', ignore_errors: true }
401
446
402
447
# ...
403
448
404
449
.. code-block :: xml
405
450
406
- <!-- # app/config/config.xml -->
407
- <imports >
408
- <import resource =" parameters.yml" />
409
- <import resource =" /etc/sites/mysite.com/parameters.yml" ignore-errors =" true" />
410
- </imports >
451
+ <!-- app/config/config.xml -->
452
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
453
+ <container xmlns =" http://symfony.com/schema/dic/services"
454
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
455
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
456
+ http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
411
457
412
- <!-- ... -->
458
+ <imports >
459
+ <import resource =" parameters.yml" />
460
+ <import resource =" /etc/sites/mysite.com/parameters.yml" ignore-errors =" true" />
461
+ </imports >
462
+
463
+ <!-- ... -->
464
+ </container >
413
465
414
466
.. code-block :: php
415
467
0 commit comments