我开发了一个小包,提供标签 Cloud 功能 . 将其包含在其他Symfony项目中应该很容易,因此需要进行配置 . 我发现3页:
我一直在使用这些示例,但很明显,我错过了一些东西,因为当我使用 php app/console config:dump-reference
时,我收到以下错误消息:
[Symfony \ Component \ Config \ Exception \ 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 /”导入博客/应用/配置/ config.yml“) .
和
[Symfony \ Component \ DependencyInjection \ Exception \ InvalidArgumentException]没有扩展能够加载“loew_tag”的配置(在/home/somePath/blog/app/config/../../src/Loew/TagBundle/资源/配置/ config.yml) . 寻找名称空间“loew_tag”,找到“框架”,“安全”,“树枝”,“monolog”,“swiftmailer”,“资产”,“学说”,“sensio_framework_extra”,“博客”,“fos_user”,“调试“,”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 回答
终于解决了这个问题
_999_记住命名惯例,尤其是Jakub Zalas指出的部分
$loader->load('config.yml');
.显然,配置文件将在服务加载后立即自动加载 .