Skip to content
Advertisement

Slim 3: how to access settings?

Before the Slim 3 is released, 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 SlimApp($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 this error below:

Notice: Undefined property: SlimApp::$settings in /…

So I can’t use $app->settings anymore? What should I use then?

Advertisement

Answer

You can get settings like this:

$container = $app->getContainer();
$settings = $container->get('settings');
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement