9

I have some general parameters I would like to share all along my application like path information ("baseurl"). Where would you ideally store this information in Silex?

herrjeh42
  • 2,782
  • 4
  • 35
  • 47

2 Answers2

12

After writing this question I came across the ConfigServiceProvider:

You can store your config data in json or yml files and access them through $app["name.of.config.var"].

Replacements to add values dynamically to the config files on setup are also supported. The only thing I did not manage so far is to inject the baseurl via the $app["request"] api into the config files.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
herrjeh42
  • 2,782
  • 4
  • 35
  • 47
  • 7
    I recommend that you get the baseUrl from the request directly when you need it. – igorw Nov 05 '12 at 15:29
  • To https://github.com/igorw/ConfigServiceProvider I would recommend https://github.com/Incenteev/ParameterHandler – Jekis Oct 01 '14 at 21:01
4

I would store it in Silex\Application. It's a DI-container based on Pimple, so you can just do:

$app['baseUrl'] = '/';

Since $app pretty much gets passed around everywhere, you will also have access to this everywhere.

Evert
  • 93,428
  • 18
  • 118
  • 189
  • 2
    I have a config.php file which I include after the `Application` instance has been bootstrapped, it just sets config values on `$app`. This is the best solution. – Maerlyn Nov 06 '12 at 07:38