[英]Adding items to Symfony2 parameters array
我有一個由許多捆綁軟件組成的Symfony2(2.8.1)應用程序。 我想有一個“關於”頁面,顯示每個捆綁軟件的版本。 為此,我嘗試使用如下參數數組:
revision:
'bundle1':
version: 1.0.0
build: 42
'bundle2':
version: 1.2.0
build: 4242
等等。 如果我將所有內容都放在一個YAML文件中,那么它將起作用。 相反,我希望每個捆綁包都定義其修訂版。 諸如:bundle1的參數文件:
revision:
'bundle1':
version: 1.0.0
build: 42
和bundle2的參數文件:
revision:
'bundle2':
version: 1.2.0
build: 4242
如果我這樣做,則僅使用最后包含的yaml文件的值填充修訂數組。 是否可以將條目“添加”到不同yaml文件中定義的參數數組中? 斯特凡諾
我改變了方法並解決了問題。 我沒有在版本中添加修訂信息,而只是在每個捆綁軟件的config文件夾中創建Yaml文件。 然后,我將yaml文件內容加載到要在About頁面中使用的數組中。
代碼類似於:
# first place to check is app config folder
$kernel_root=$this->get('kernel')->getRootDir();
$toLocate[]=$kernel_root.'/config';
# then get config folder for each active bundle
$kernel = $this->get('kernel');
$configDirectories=$this->getParameter('kernel.bundles');
foreach ($configDirectories as $bundleName => $configDirectory) {
$toLocate[]= $kernel->locateResource('@'.$bundleName).'Resources/config';
}
# now get array of revision files
$locator = new FileLocator($toLocate);
$yamlRevFiles = $locator->locate('revision.yml', null, false);
# and finally create array of date read from revision files
$revs=array();
foreach ($yamlRevFiles as $yamlRevFile) {
$revs[]=Yaml::parse($yamlRevFile);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.