Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Description
Thecookbook page on extensions recommends avoiding semantic configuration if it's not needed:
When you create a bundle, you have two choices on how to handle configuration:
Normal Service Configuration (easy):
...Exposing Semantic Configuration (advanced):
...The second option - which you'll learn about in this article - is much more flexible, but also requires more time to setup. If you're wondering which method you should use,it's probably a good idea to start with method#1, and then change to#2 later if you need to.
On the other hand, thecookbook page on bundle best practices recommends using semantic configuration even in simpler applications:
To provide more flexibility, a bundle can provide configurable settings by using the Symfony2 built-in mechanisms.
For simple configuration settings, rely on the default parameters entry of the Symfony2 configuration. Symfony2 parameters are simple key/value pairs; a value being any valid PHP value. Each parameter name should start with the bundle alias, though this is just a best-practice suggestion. The rest of the parameter name will use a period (.) to separate different parts (e.g. acme_hello.email.from).
The end user can provide values in any configuration file:
# app/config/config.ymlparameters: acme_hello.email.from: fabien@example.comRetrieve the configuration parameters in your code from the container:
$container->getParameter('acme_hello.email.from');Even if this mechanism is simple enough, you are highly encouraged to use the semantic configuration described in the cookbook.