【发布时间】:2016-07-03 03:22:34
【问题描述】:
我正在尝试加载自定义配置但出现异常:
YamlFileLoader.php 中的 1/2 InvalidArgumentException
没有扩展能够加载配置 “cwiczenia”(在 ..\app/config\config.yml 中)。看了 对于命名空间“cwiczenia”,找到“框架”, “安全”,...
2/2 FileLoaderLoadException
没有扩展能够加载“cwiczenia”的配置...
..\src\CwiczeniaDependencyInjectionBundle\DependencyInjection\Configuration.php
namespace CwiczeniaDependencyInjectionBundle\DependencyInjection;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
class Configuration implements ConfigurationInterface{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('cwiczenia');
$rootNode
->children()
->scalarNode('teamName')->end()
->end();
return $treeBuilder;
..\src\CwiczeniaDependencyInjectionBundle\DependencyInjection\CwiczeniaExtension.php
namespace CwiczeniaDependencyInjectionBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
class CwiczeniaExtension extends Extension
{
protected function load(array $configs, ContainerBuilder $container)
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
public function getAlias()
{
return 'cwiczenia';
}
..\app\config\config.yml
cwiczenia:
teamName: Lakers
AppKernel
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new SandersBundle\SandersBundle(),
new CwiczeniaDependencyInjectionBundle\CwiczeniaDependencyInjectionBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
如果我删除 Configuration.php 会出现同样的异常
【问题讨论】:
标签: symfony