settings.php文件代码
with open("test.txt") as f:
lines = f.readlines()
new_lines = [line.replace("interface Vlan101", "vrf forwarding ABC" for line in lines]
with open("out.txt", "w") as f1:
f1.writelines(new_lines)
index.php文件代码
return [
'settings' => [
'displayErrorDetails' => true, // set to false in production
'addContentLengthHeader' => false, // Allow the web server to send the content-length header
'encryption_key' => 'key1',
'jwt_secret' => 'secret1',
'db' => [
'servername' => 'localhost',
'username' => 'user',
'password' => 'pwd',
'dbname' => 'db',
],
],];
我收到错误: 在不在
中的对象上下文中时使用$ this如何在中间件中获取设置属性?
答案 0 :(得分:2)
在这个上下文中,$ this应该是Slim Container对象。
设置存储为数组,可以这样访问:
$app->add(function (Request $request, Response $response, $next) {
/* @var Container $this */
$settings = $this->get('settings');
$jwtSecret = $settings['jwt_secret'];
// Do something...
return $next($request, $response, $next);
});