我试图加载自定义配置但获得异常:
YamlFileLoader.php中的1/2 InvalidArgumentException
没有可以加载配置的扩展程序 " cwiczenia" (在.. \ app / config \ config.yml中)。查看 for namespace" cwiczenia",found" framework", "安全",...
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';
}
.. \应用\配置\ 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
,则会出现相同的异常答案 0 :(得分:3)
您必须手动注册扩展类,如何在此处描述http://symfony.com/doc/current/cookbook/bundles/extension.html#manually-registering-an-extension-class
这样的事情:
//.....
class CwiczeniaDependencyInjectionBundle extends Bundle
{
public function getContainerExtension()
{
if (null === $this->extension) {
$this->extension = new CwiczeniaExtension();
}
return $this->extension;
}
}
答案 1 :(得分:2)
我有同样的问题,并修复它。
要注册分机,您需要为分机和分机添加相同的名称。因此,如果您希望将扩展程序设为cwiczenia
,则必须将扩展程序文件命名为CwiczeniaExtention
,并且必须将该程序包命名为CwiczeniaBundle
。
或者,如果您不想更改套件名称(CwiczeniaDependencyInjectionBundle
),则必须将扩展程序重命名为CwiczeniaDependencyInjectionExtension
,然后才能将配置加载为cwiczenia_dependency_injection
。
或者您可以手动注册扩展名,如上所述@helios