[英]Load config/parameters yml based on value in symfony2 controller
我想創建這個:
MyBundle/resources/config/settings/site1.yml
MyBundle/resources/config/settings/site2.yml
MyBundle/resources/config/settings/site3.yml
我可以在每個人里面放哪里:
parameterWidth: 230
parameterHeight: 145
有人可以幫我創建擴展名,以便我可以在基於變量(1,2,3)的控制器中使用這些值來加載特定的配置嗎?
我已經閱讀了有關擴展的文檔( http://symfony.com/doc/current/cookbook/bundles/extension.html ),但是它們都沒有幫助我。
任何幫助將不勝感激
假設您將站點編號存儲在site參數中,則在捆綁軟件的DependencyInjection擴展中,您可以執行以下操作:
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$this->processConfiguration($configuration, $configs);
$file = 'default.yml';
if ($container->hasParameter('site')) {
$file = 'site'.$container->getParameter('site');
}
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/settings'));
$loader->load($file);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.