A parameters.yml per bundle, symfony2(每个包一个 parameters.yml,symfony2)
问题描述
我想知道是否可以为每个包定义一个 parameters.yml 文件,或者只为需要它的包定义并加载它们.
I was wondering if it's possible to defined a parameters.yml file for every bundle or only for the bundles that need it and load those.
我已经搜索了很多,但我找不到这样的解决方案.
I have searched a lot but i can't find such solution.
推荐答案
你应该澄清一下;您希望每个捆绑包都自动包含一个 parameters.yml 文件吗?恐怕您需要修改 Symfony 的 DI 核心.不过有一个简单的替代方案.
You should clarify a bit; you want every single bundles to automatically include a parameters.yml file? I am afraid you would need to modify Symfony's DI core. There is an easy alternative though.
如果您使用一些 DependencyInjection 创建自己的包,那么您可以在包的扩展类中添加 $loader->load('parameters.yml');.
If you create your own bundle with some DependencyInjection then you can add $loader->load('parameters.yml'); in the bundle's extension class.
扩展类应该位于YourBundle/DependencyInjection/YourBundleExtension.php.
该类应如下所示
class YourBundleExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new LoaderYamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('parameters.yml'); // Adding the parameters file
}
}
因此,在这种情况下,parameters.yml 文件将位于 YourBundle/Resources/config/parameters.yml 中.
So in this case the parameters.yml file would be in YourBundle/Resources/config/parameters.yml.
这篇关于每个包一个 parameters.yml,symfony2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:每个包一个 parameters.yml,symfony2
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
