我将尝试定义我的捆绑包用户可用的配置参数,但是我遇到了一个问题:无法识别根节点。
我创建了一个名为“Configuration”的类,并编写了一个名为“getConfigTreeBuilder”的函数,代码如下:
然而,当试图加载该配置时,出现了以下错误:
最接近的是
如果我删除我的捆绑包的配置部分和 dump-reference,我会得到这个:
我创建了一个名为“Configuration”的类,并编写了一个名为“getConfigTreeBuilder”的函数,代码如下:
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('rally_stats');
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
$rootNode->children()->arrayNode('projects')
->prototype('scalar')->end();
return $treeBuilder;
}
使用这个,我希望能够在config.yml
中创建一个类似于以下的部分:
rally_stats:
projects:
- project1
- project2
然后可以使用以下方式访问配置:
$this->getContainer()->getParameter('rally_stats.projects');
然而,当试图加载该配置时,出现了以下错误:
[Symfony\Component\Config\Exception\FileLoaderLoadException]
There is no extension able to load the configuration for "rally_stats"
(in /Users/stu/Projects/rally-stats/app/config/config.yml). Looked for namespace "rally_stats", found "framework", "security", "
twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra",
"wa_ndisco_rally_stats", "jms_di_extra", "jms_aop", "debug", "web_profiler", "sensio_distribution"
in /Users/stu/Projects/rally-stats/app/config/config.yml
(which is being imported from "/Users/stu/Projects/rally-stats/app/config/config_dev.yml").
最接近的是
wa_ndisco_rally_stats
,这是 Symfony 生成捆绑包时的原始根名称。我已经搜索了这个和 wa_ndisco
,但没有其他引用。如果我删除我的捆绑包的配置部分和 dump-reference,我会得到这个:
# Default configuration for "WANdiscoRallyStatsBundle"
rally_stats:
projects: []
为什么我不能使用我提供的节点名称添加配置?
如果我确实给它了它认为应该有的名称wa_ndisco_rally_stats
,我也无法访问它,对于这个名称我得到了相同的错误。
WANdisco\RallyStatsBundle\DependencyInjection
命名空间中的 Configuration 类,您可以从那里看到 bundle 名称... - Stuart Grimshawload()
。感谢您的建议... - Stuart Grimshaw