简介
我知道。关于这个确切主题有成千上万的帖子,但不知何故我仍然无法解决这个问题。我总是收到错误
没有扩展能够加载“第一”的配置(在/var/www/app/src/tzfrs/SpotifyBundle/DependencyInjection/../Resources/config/settings.yml)。查找命名空间“first”,没有找到
目的
我创建了一个包并想要自定义配置选项,但由于它们比普通文件大,我不想将它放在 config.yml
中,而是放在我自己的文件中。
描述
我的捆绑项目结构如下所示 /src/tzfrs/SpotifyBundle
在包中我创建了文件
./TzfrsSpotifyBundle.php
./DependencyInjection/Configuration.php
./DependencyInjection/TzfrsSpotifyExtension.php
./Resources/config/settings.yml
当然,我已经在 AppKernel
中注册了 Bundle,到目前为止,除了我要添加的新配置外,该 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意思是像我的包一样命名根元素。还是一样的错误
最佳答案
确保您的所有内容都拼写正确,并且您的扩展类确实被调用了。如果您没有正确命名扩展名,那么它将不会被加载。我刚刚对此进行了测试,它运行良好:
cerad_spotify:
first:
secondary: false
class CeradSpotifyBundle extends Bundle
{
}
namespace Cerad\SpotifyBundle\DependencyInjection;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('cerad_spotify');
$rootNode
->children()
->arrayNode('first')
->children()
->booleanNode('secondary')->end()
->end()
->end() // first
->end()
;
return $treeBuilder;
}
}
namespace Cerad\SpotifyBundle\DependencyInjection;
class CeradSpotifyExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
VarDumper::dump($config);
}
}
关于php - 没有能够加载配置的扩展...查找命名空间 "...",没有找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39746702/