symfony - Where to write server-specific parameters? -
for custom bundles of application, need define parameters (mainly folder/file path). of them different depending on if i'm on local test server or remote prod server , common both.
how should manage these parameters?
i had idea create such kind of file:
- myfirstbundle/resources/config/parameters_local.yml
- myfirstbundle/resources/config/parameters_distant.yml
- mysecondbundle/resources/config/parameters_local.yml
- mysecondbundle/resources/config/parameters_distant.yml
and import them respectively in app/config/parameters_local.yml:
imports: - { resource: @myfirstbundle/resources/config/parameters_local.yml } - { resource: @mysecondbundle/resources/config/parameters_local.yml }
and app/config/parameters_distant.yml:
imports: - { resource: @myfirstbundle/resources/config/parameters_distant.yml } - { resource: @mysecondbundle/resources/config/parameters_distant.yml }
but bit heavy, when have 1 or 2 parameters in bundle or when have parameters common local , distant server.
what way that?
as explained here, can define default configuration in bundle prod environment :
// src/acme/hellobundle/dependencyinjection/configuration.php namespace acme\hellobundle\dependencyinjection; use symfony\component\config\definition\builder\treebuilder; use symfony\component\config\definition\configurationinterface; class configuration implements configurationinterface { public function getconfigtreebuilder() { $treebuilder = new treebuilder(); $rootnode = $treebuilder->root('acme_hello'); $rootnode ->children() ->scalarnode('my_param_1')->defaultvalue('foo')->end() ->scalarnode('my_param_2')->defaultvalue('bar')->end() ->end(); return $treebuilder; } }
and in app/config/config_dev.yml override parameters different prod ones :
# app/config/config_dev.yml acme_hello: my_param_2: baz
et hop !
Comments
Post a Comment