[英]Where do I store general config parameters in Silex?
I have some general parameters I would like to share all along my application like path information ("baseurl"). 我有一些一般参数,我想在我的应用程序中共享,如路径信息(“baseurl”)。 Where would you ideally store this information in Silex?
您最好将这些信息存储在Silex中?
After writing this question I came across the ConfigServiceProvider
: 写完这个问题后,我遇到了
ConfigServiceProvider
:
You can store your config data in json or yml files and access them through $app["name.of.config.var"]
. 您可以将配置数据存储在json或yml文件中,并通过
$app["name.of.config.var"]
访问它们。
Replacements to add values dynamically to the config files on setup are also supported. 还支持在设置时动态添加值到配置文件的替换。 The only thing I did not manage so far is to inject the baseurl via the
$app["request"]
api into the config files. 到目前为止我唯一没有管理的是通过
$app["request"]
api将baseurl注入配置文件。
I would store it in Silex\\Application
. 我会将它存储在
Silex\\Application
。 It's a DI-container based on Pimple, so you can just do: 这是一个基于Pimple的DI容器,所以你可以这样做:
$app['baseUrl'] = '/';
Since $app
pretty much gets passed around everywhere, you will also have access to this everywhere. 由于
$app
几乎遍布各地,您也可以随处访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.