-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Cookbook][Configuration] add configuration cookbook handlig parameters in Configurator class #3420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
243c0d1
ec13feb
c07c655
28c144a
a6bda5e
ad27a83
9710bb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,17 @@ | ||
.. index:: | ||
single: Using Configuration Parameters | ||
|
||
Using Configuration Parameters | ||
============================== | ||
|
||
Parameters, such as ``kernel.root_dir`` (pointing to a path) or ``kernel.debug`` | ||
(whether debug mode is enabled), are common in configuration. By wrapping the | ||
parameter name within 2 ``%`` characters, you indicate that this value should | ||
be replaced by the value of the parameter. When using Symfony, you can have | ||
parameters defined in a bundle and used only in that bundle and also parameters | ||
defined in a bundle and used in another. Usually they would have a name | ||
like ``demo_bundle.service_doer.local_parameter`` making explicit where this | ||
parameter comes from. If the parameter is global then it may not have a | ||
namespace, e.g. ``%some_global_option_here%``. | ||
|
||
Basic Usage | ||
----------- | ||
|
||
You can use parameters inside the ``parameters.yml`` file: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/parameters.yml | ||
parameters: | ||
payment_test_mode: "%kernel.root_dir%" | ||
|
||
Inside ``config.yml`` and other configuration files building larger | ||
strings: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/config.yml | ||
my_bundle: | ||
local: | ||
directory: "%kernel.root_dir%/../web/media/image" | ||
|
||
.. code-block:: xml | ||
|
||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
my-bundle="http://example.org/schema/dic/my_bundle"> | ||
<my-bundle:config> | ||
<my-bundle:local directory="%kernel.root_dir%/../web/media/image" /> | ||
</my-bundle:config> | ||
</container> | ||
|
||
.. code-block:: php | ||
|
||
$container->loadFromExtension('my_bundle', array( | ||
'local' => array( | ||
'directory' => '%kernel.root_dir%/../web/media/image', | ||
), | ||
)); | ||
|
||
For more information on how parameters are used in Symfony please see | ||
:ref:`parameters <book-service-container-parameters>`. | ||
|
||
Besides these usages above you can use this syntax in routing files and handle | ||
parameters in special cases as discussed below. | ||
|
||
Using Parameters in your Bundle Configuration | ||
--------------------------------------------- | ||
|
||
If for instance, there is a use case in which you want to use the | ||
``%kernel.debug%`` debug mode parameter to make your bundle adapt its | ||
configuration depending on this. For this case you cannot use | ||
the syntax directly and expect this to work. The configuration handling | ||
will just treat this ``%kernel.debug%`` as a string. Consider | ||
this example with the AcmeDemoBundle:: | ||
single: Using Parameters Within A Dependency Injection Class | ||
|
||
Using Parameters Within A Dependency Injection Class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
---------------------------------------------------- | ||
|
||
You have seen how to use configuration parameters within | ||
:ref:`Symfony service container <book-service-container-parameters>`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Symfony service containers (plural) |
||
There are special cases such as when you want, for instance, to use the | ||
``%kernel.debug%`` parameter to make the services in your bundle enter | ||
debug mode. For this case there is more work to do in order | ||
to make the system understand the parameter value. By default | ||
your parameter ``%kernel.debug%`` will be treated as a | ||
simple string. Consider this example with the AcmeDemoBundle:: | ||
|
||
// Inside Configuration class | ||
$rootNode | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,4 +124,4 @@ path): | |
.. seealso:: | ||
|
||
For other usages of the parameter ``%`` syntax see | ||
:doc:`Using Configuration Parameters </cookbook/using_configuration_parameters>`. | ||
:doc:`Using Parameters Within A Dependency Injection Class </cookbook/using_parameters_in_dic>`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't have to use the title here: :doc:`</cookbook/using_parameters_in_dic>`. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, the document is located at ``/cookbook/configuration/using_parameters_in_dic`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to use the title here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, the document is located at ``/cookbook/configuration/using_parameters_in_dic`.