Lajdák Marek
Lajdák Marek

Reputation: 3089

Symfony 3 own global configuration file

How i can create and use own global config with keys/values in symfony? I was try set keys/values in parameters.yml under parameters line which been in this file after instalation and get it like $pageTitle = $this->getParameter('myKey'); and it works but i want own whole config file with structure for ex. $this->getParameter('myParameters.myKey') so:

I was created new file:

#app/config/myConfig.yml

myParameters:
    myKey: myValue

In config.yml i added:

#app/config/config.yml

imports:
    - { resource: myConfig.yml }

and in controller:

$pageTitle = $this->getParameter('myKey');

And i have exception:

FileLoaderLoadException in FileLoader.php line 118: There is no extension able to load the configuration for "inyconfig" (in....

EDIT


This example works but you must do one little change - myParameters change to parameters and everything is work like a charm.

Upvotes: 0

Views: 266

Answers (2)

mduvernon
mduvernon

Reputation: 498

You have to do a dependency injection e.g. BundleNameDependencieInjection related of your bundle and then create Configuration class that provide configure external dependence and/or external configurations

Have a look there http://symfony.com/doc/current/bundles/configuration.html#processing-the-configs-array

In parameters you can create some scalar or array variables that can be called in some circumstances in your case you may create an array with some range like that :

parameters:
# scalar
   one.two.three:    something 
# array
   oneBis:
      twoBis: 
         threeBis:   somethingBis

Upvotes: 1

Daniella
Daniella

Reputation: 129

Use parameters instead of myParameters.

So, put in app/config/myConfig.yml:

parameters:
    myKey: myValue

Upvotes: 1

Related Questions