我设置了一个bundle,它通过Configuration.php和config 3构建器定义了一些选项,它位于bundle中。
我想把配置放到/root/app/config/config文件中。通过
让配置在包中可用。$config = $container->getParameter('namespace');
到目前为止,我可以通过
看到配置可用。bin/console debug:config namespace
但是如果我通过
在bundle代码中获得配置$config = $container->getParameter('namespace');
抛出一个异常:"参数"namespace"必须被定义",它是定义的,但异常告诉我不是这样的。
My current Configuration.php:
class NamespaceExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader'YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
我在这里错过了什么?
您误解了配置和参数。如果您希望通过参数访问您的配置,您应该根据您的配置设置一个参数:
$container->setParameter('namespace', $config['namespace']);