当我想为捆绑包创建配置参数时,我获得了此错误。
的Symfony \元器件\ DependencyInjection \异常\ InvalidArgumentException] 没有可以加载配置的扩展 “mrc_morales_tyre”
这是代码:
应用程序/配置/ config.yml
mrc_morales_tyre:
db_driver: orm
的configuration.php
namespace MrcMorales\TyreBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('mrc_morales_tyre');
$supportedDrivers = array('orm');
$rootNode
->children()
->scalarNode('db_driver')
->validate()
->ifNotInArray($supportedDrivers)
->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers))
->end()
->end()
->end();
return $treeBuilder;
}
}
TyreExtension.php
namespace MrcMorales\TyreBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Config\Definition\Processor;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class TyreExtension extends Extension
{
/**
* {@inheritdoc}
*/
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'));
}
}
TyreBundle.php
namespace MrcMorales\TyreBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use MrcMorales\TyreBundle\DependencyInjection\Compiler\ValidationPass;
class TyreBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new ValidationPass());
}
}
ValidationPass是在非常规文件夹中加载validation.yml并且它可以正常工作。
由于
答案 0 :(得分:0)
解决:
Symfony默认情况下比config var name是扩展名,在这种情况下是轮胎。
然后我需要将扩展名更改为MrcMoralesTyreExtension,但我们需要覆盖方法getContainerExtension():
TyreBundle.php
public function getContainerExtension()
{
return new MrcMoralesTyreExtension();
}