From 0ff34cbf9b5697fb2f66c2294a91178ec6202902 Mon Sep 17 00:00:00 2001 From: Parham Doustdar Date: Tue, 20 Jan 2015 13:12:53 +0330 Subject: [PATCH] Update README.md Added more explanation and two examples for reading configuration files with and without a prefix. --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 1950a9a..d39a8ec 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,22 @@ Or in nginx with fcgi: fastcgi_param APP_ENV dev +Configuration values are set on the `$app` object. For example, to retrieve the `debug` configuration value, you can simply access the `debug` key of `$app`. + + $app->get('/', function() use ($app) { + echo $app['debug']; + }); + +In order to prevent your configuration from overriding the keys that might be set on the application, you can pass in a `prefix` to the constructor. This prefix will then be available as a key under which all your other configuration can be accessed: + + $app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__."/../config/$env.json", array(), null, 'example')); + +You can now access the `debug` value defined in your configuration like this: + + $app->get('/', function() use ($app) { + echo $app['example']['debug']; + }); + ### Replacements Also, you can pass an array of replacement patterns as second argument.