在Slim 3发布之前,以下代码可以正常工作:
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']; }
但在发布后,我收到以下错误:
注意:未定义的属性:/中的Slim\App :: $ settings
所以我不能再使用$app->settings
了?那我应该怎么用?
你可以得到这样的设置:
$container = $app->getContainer(); $settings = $container->get('settings');
您可以通过$ this访问设置路由callables
$modulesSettings = $this->get('settings')['modules']['local'];
有关更多信息,请阅读此处