我有一个名为Web \ CoworkerBundle的Bundle。在DIC / Configuration.php中我有:
$rootNode = $treeBuilder->root('web_coworker');
$rootNode
->children()
->scalarNode('redirect_url')->defaultNull()->end()
->end();
在config.yml中我有:
web_coworker:
redirect_url: "http://www.example.com/"
现在在我的DefaultController.php中,我做
return array(
'url' => $this->container->getParameter('redirect_url')
);
我收到错误
参数" redirect_url"必须定义。
我错过了什么吗?
答案 0 :(得分:14)
您需要在捆绑中创建扩展程序( Acme / DemoBundle / DependencyInjection )
class AcmeDemoBundleExtension extends Extension
{
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');
// MOST IMPORTANT LINE
$container->setParameter('web_coworker.params', $config);
}
}
现在关于控制器,您可以删除您返回的内容,这应该可以解决问题:)