Symfony2中的自定义配置

时间:2015-08-13 14:53:06

标签: php symfony config

我开发了一个小包,提供标签云功能。将其包含在其他Symfony项目中应该很容易,因此需要进行配置。我发现了3页:

我参与了这些示例,但很明显,我错过了一些内容,因为当我使用php app/console config:dump-reference时收到以下错误消息:

  

[Symfony的\元器件\配置\异常\ FileLoaderLoadException]   没有扩展程序可以加载" loew_tag" (在somePath / blog / app / config /../../ src / Loew / TagBundle / Resources / config / config.yml中)。寻找命名空间" loew_tag",找到" ......"在somePath / blog / app / config /../../ src / Loew / TagBundle / Resources / config / config.yml(从" somePath / blog / app / config / config.yml&#导入) 34。)

  

[Symfony的\元器件\ DependencyInjection \异常\ InvalidArgumentException]
  没有扩展程序可以加载" loew_tag" (在/home/somePath/blog/app/config/../../src/Loew/TagBundle/Resources/config/config.yml)。寻找命名空间" loew_tag",找到"框架","安全"," twig"," monolog",& #34; swiftmailer"," assetic"," doctrine"," sensio_framework_extra","博客"," fos_user&# 34;,"调试"," web_profiler"," sensio_distribution"

我在一个'博客包中工作'并尝试访问'标记包'。

的配置数据

我的' app / config / config.yml':

的顶部
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: ../../src/Loew/TagBundle/Resources/config/services.yml }
- { resource: ../../src/Loew/TagBundle/Resources/config/config.yml }

LoewTagExtension.php:

<?php
// Loew/TagBundle/DependencyInjection/LoewTagExtension.php

namespace Loew\TagBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

class LoewTagExtension extends Extension
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        //$container->setParameter('food_entities',     $config['food_entities']);
        $container->setParameter('split_match', $config['split_match']);

        $loader = new Loader\YamlFileLoader($container, new   FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('config.yml');
        $loader->load('services.yml');
        }
    }

config.yml:

loew_tag:
#    food_entities:
#     - "BlogBundle:Article"
#     - "BlogBundle:Comment"
    split_match: "/[^0-9a-zA-ZöÖüÜäÄß]/"

的configuration.php:

<?php
// Loew/TagBundle/DependencyInjection/Configuration.php


namespace Loew\TagBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritdoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();

        $rootNode = $treeBuilder->root('loew_tag');

        $rootNode
            ->children()
            ->scalarNode('split_match')->end()
//                ->arrayNode('food_entities')
//                ->prototype('scalar')->end()

            ->end();

        return $treeBuilder;
    }
}

节点food_entities的条目在所有文件中都被注释,以使其尽可能简单。

我注意到,类似的问题已被提出,问题已经解决,但我无法将这些问题转移到这个问题上。

任何想法,我错过了什么?

1 个答案:

答案 0 :(得分:0)

最后通过

解决了这个问题
  • 记住命名惯例,特别是Jakub Zalas指出的部分
  • 从扩展程序文件中删除条目timestamp

显然,配置文件会在服务加载后自动加载。