Symfony2:捆绑包配置在容器中不可用

Symfony2: Bundle Configuration not available in container

我设置了一个包,它通过 Configuration.php 和位于包内的配置三构建器定义了一些选项。

我想将配置放入 /root/app/config/config.yml 文件中,但要通过

在捆绑包中提供配置
$config = $container->getParameter('namespace');

到目前为止,我可以通过

看到可用的配置
bin/console debug:config namespace

但是如果我通过

获得捆绑代码中的配置
$config = $container->getParameter('namespace');

抛出一个异常:"The parameter "namespace" must be defined" which it is, but the exception shall me otherwise.

我现在的 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']);