【发布时间】:2016-09-28 11:53:17
【问题描述】:
简介
我知道。关于这个确切的主题有成千上万的帖子,但不知何故我仍然无法解决这个问题。我总是收到错误
There is no extension able to load the configuration for "first" (in /var/www/app/src/tzfrs/SpotifyBundle/DependencyInjection/../Resources/config/settings.yml). Looked for namespace "first", found none
目的
我创建了一个包并希望有自定义配置选项,但由于它们比普通文件大,我不想把它放在config.yml 中,而是放在我自己的文件中。
说明
我的 bundle 项目结构如下/src/tzfrs/SpotifyBundle
在包中我创建了文件
./TzfrsSpotifyBundle.php./DependencyInjection/Configuration.php./DependencyInjection/TzfrsSpotifyExtension.php./Resources/config/settings.yml
当然,我已经在 AppKernel 中注册了 Bundle,到目前为止,除了我要添加的新配置之外,该包一切正常
TzfrsSpotifyBundle的内容
<?php
namespace tzfrs\SpotifyBundle;
use tzfrs\SpotifyBundle\DependencyInjection\TzfrsSpotifyExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class TzfrsSpotifyBundle extends Bundle
{
}
/DependencyInjection/Configuration.php 的内容(最小化为相关信息)
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('first');
$rootNode
->children()
->booleanNode('secondary')->defaultTrue()->end()
->end();
return $treeBuilder;
}
./DependencyInjection/TzfrsSpotifyExtension.php 的内容(最小化为相关信息)
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('settings.yml');
}
./Resources/config/settings.yml的内容
first:
secondary: false
想法
如果有任何问题或建议不起作用,我将使用信息更新此部分
- 我尝试的方法与此帖子建议的https://stackoverflow.com/a/36051719/2823419 相同,但没有成功。我遇到了同样的错误。
- 然后我尝试了这个答案https://stackoverflow.com/a/35505189,意思是像我的包一样命名根元素。还是一样的错误
【问题讨论】:
-
我假设您已经检查了手册? symfony.com/doc/current/bundles/configuration.html 您的根节点将类似于 tzfrs_spotify 这就是 Symfony 知道特定捆绑包的配置值的方式。也许也可以看看框架包配置文件。
-
是的,我检查过,但也没有用。