[英]Symfony2: There is no extension able to load the configuration for
I am building an extension to load config files from all installed bundles. 我正在构建一个扩展来从所有已安装的bundle加载配置文件。
my Extension looks like this: 我的扩展看起来像这样:
namespace Acme\MenuBundle\DependencyInjection;
// use ...
use Acme\MenuBundle\DependencyInjection\Configuration;
class AcmeMenuExtension extends Extension {
public function load(array $configs, ContainerBuilder $container) {
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$finder = new \Symfony\Component\Finder\Finder();
$finder
->directories()
->in($container->getParameter('kernel.root_dir') . '/../src/*/*Bundle/Resources')
->path('config');
$possibleLocations = array();
foreach ($finder as $c_dir) {
$possibleLocations[] = $c_dir->getPathName();
}
$loader = new Loader\YamlFileLoader($container, new FileLocator($possibleLocations));
$loader->load('menu.yml');
}
}
And then there is my (very simple) Configuration class: I will add a more complex tree in the future, but for now I want it to work with this: 然后是我的(非常简单的)Configuration类:我将来会添加一个更复杂的树,但是现在我希望它可以使用它:
namespace Acme\MenuBundle\DependencyInjection;
// use ...
class Configuration implements ConfigurationInterface {
public function getConfigTreeBuilder() {
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('mw_menu');
$rootNode
->children()
->scalarNode('mw_menu')->defaultValue('')->end()
->end();
return $treeBuilder;
}
}
For testing I only placed a "menu.yml" file inside the current MenuBundle\\Resources\\config with this content: 为了测试我只在当前的MenuBundle \\ Resources \\ config中放置了一个“menu.yml”文件,其中包含以下内容:
# file: src\Acme\MenuBundle\Resource\config\menu.yml
mw_menu: "some teststring"
For manual testing I use a testAction in a default Controller, which does actually nothing but render an empty template. 对于手动测试,我在默认的Controller中使用了一个testAction,它实际上只是呈现一个空模板。
Anyway, I get this error: 无论如何,我得到这个错误:
InvalidArgumentException: There is no extension able to load the configuration for
"mw_menu" (in {path to symfony}/app/../src/Acme/MenuBundle/Resources\config\menu.yml).
Looked for namespace "mw_menu", found none
How can I fix that? 我该如何解决这个问题?
From what I currently understand, Symfony notices the key 'mw_menu' in the config file, but is not able to find the matching configuration. 根据我目前的理解,Symfony注意到配置文件中的密钥“mw_menu”,但无法找到匹配的配置。
I worked along the cookbook article: How to expose a semantic configuration? 我在烹饪书文章中工作: 如何公开语义配置?
Please note: I know of Knp Menu Bundle and similar Bundles but I do want to implement a menu myself. 请注意:我知道Knp Menu Bundle和类似的Bundles,但我想自己实现一个菜单。
Additionally I found this notice. 另外我发现了这个通知。 Is he right? 他是对的吗?
That's because your code: 那是因为你的代码:
$rootNode = $treeBuilder->root('mw_menu');
$rootNode
->children()
->scalarNode('mw_menu')->defaultValue('')->end()
->end();
means that the config file should look like this: 意味着配置文件应如下所示:
mw_menu:
mw_menu: "some teststring"
To be more specific, you need to adapt your code to whatever node you want. 更具体地说,您需要使代码适应您想要的任何节点。 In general, people use a general root, like mw_menu
, and then secondary value like database_driver
in the following example: 通常,人们使用通用根,如mw_menu
,然后在下面的示例中使用像database_driver
这样的辅助值:
$rootNode = $treeBuilder->root('mw_menu');
$rootNode
->children()
->scalarNode('database_driver')->defaultValue('orm')->end()
->end();
Which would then look like this in config file: 在配置文件中,这将是这样的:
mw_menu:
database_driver: mongo_db
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.