添加新服务时出现此错误:
[错误4]期望开始标记,'<'未找到(在n / a - 第1行,第1列)
这是新的services.yml
文件:
parameters:
acme_foo.class: Acme\FooBundle\Services\Foos
services:
acme_foo:
class: %acme_foo.class%
arguments: [@doctrine]
此文件中没有标签,只有空格。这是DependencyInjection/Configuration.php
文件:
<?php
namespace Acme\FooBundle\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('acme_foo');
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
return $treeBuilder;
}
}
和DependencyInjection/AcmeFooExtension.php
:
<?php
namespace Acme\FooBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* 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 RedconviveSubscriptionExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
知道错误在哪里?它似乎与services.yml
有关,但我已经检查了它,似乎没有。
答案 0 :(得分:8)
更改
$loader = new Loader\XmlFileLoader
到
$loader = new Loader\YamlFileLoader
DependencyInjection/AcmeFooExtension.php
中的。因为您正在加载yml
文件。