Thin 3: how to access the settings?

Before releasing Slim 3, the codes below work fine:

settings.php,

return [ 'settings' => [ 'displayErrorDetails' => true, 'modules' => [ 'core' => 'config/core/modules.php', 'local' => 'config/local/modules.php' ], ], ]; 

index.php

 // Instantiate the app $settings = require __DIR__ . '/../src/settings.php'; $app = new \Slim\App($settings); $MyClass = new MyClass($app); 

Myclass.php

 class MyClass { private $app; public function __construct($app) { $this->app = $app; $local = require $app->settings['modules']['local']; } 

But after the release, I get the following error:

Note: Undefined property: Slim \ App :: $ settings in / ...

So, I can no longer use $app->settings ? What should I use then?

+7
php slim-3
source share
3 answers

You can get the following settings:

 $container = $app->getContainer(); $settings = $container->get('settings'); 
+8
source share

You can access the routing call settings through $ this

 $modulesSettings = $this->get('settings')['modules']['local']; 

For more information, read here.

+5
source share

The address of the SLIM 3 configuration file is pro / src / settings.php, and you can add additional settings; On any route, you can access them as follows:

 var_dump($this->get('settings')['logger']); 
+1
source share

All Articles