是否可以在config.yml
文件中进行逻辑操作?
例如我试过这个:
width: 50
height: 30
width_more_height: %width% + %height%
但是我收到了错误..
答案 0 :(得分:0)
你不能像在.yml文件中写的那样去做。但是有一种方法可以让这个想法发挥作用。您可以在DependencyInjection文件夹中的包扩展文件中执行此操作。如果可以,可以将width和height参数移动到bundle,也可以创建一个CoreBundle或其他东西。
class MyExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
$sum = $container->getParameter('width') + $container->getParameter('height');
$container->setParameter('width_more_height', $sum);
}
}