Closed guice closed 9 years ago
These settings are passed into the settings key of the container.
https://github.com/slimphp/Slim/blob/3.x/Slim/Container.php#L100
We are currently discussing this on irc #slimphp on freenode if you want to hop on.
This code would never work as App doesn't load settings files.
The correct way to do it is:
$settings = require 'config.php';
$container = new \Slim\Container();
foreach ($settings as $key => $value) {
$container[$key] = $value;
}
$app = new \Slim\App($container);
If its just settings (and not pimple services) you want from the config file you can do
# config.php
return [
'key' => 'val'
];
#index.php
$app = new Slim\App(require 'config.php'); // note the require here that you forgot
But like akrabat said; services will have to be added to the container, not the app.
services will have to be added to the container, not the app.
I noticed the app itself puts everything into a container: https://github.com/slimphp/Slim/blob/3.x/Slim/App.php#L79
There doesn't actually seem to be a separation of app and container (at least on the surface).
(oops, did forget the require -- I edited the actual code to remove paths)
If we did want to change the behaviour, the PR looks like this: https://github.com/slimphp/Slim/compare/slimphp:3.x...akrabat:di-settings?expand=1
+1 for passing array to pimple.
I want to have all the config in one file, which includes the TwigView
Example: https://gist.github.com/geggleto/81cd05c5239ed56d70e2
$this->settings['view'] is where the closure is...
@akrabat can you open a PR with this so I can leave my comment on the code please. I am happy to make this change but have 1 reservation.
@guice this is now working the way you expect it to, we have merged in a PR to allow what you are after.
Awesome. Great news! Thanks @silentworks. :+1:
We're unable to leverage full Pimple due to a key pass-thru missing in Slim\Container's constructor:
Slim\Container does not pass $userSettings to the parent (Pimple) class, resulting in a failed Pimple initialization. This doesn't work:
Or should this be handled some other way within Slim? The point here is to use DI to pass in environment dependent classes, not hard code them into my index.php file.