ERROR 4期望开始标记,'<'未找到(在n / a - 第1行,第1列)

时间:2014-06-24 07:33:39

标签: php symfony service

添加新服务时出现此错误:

  

[错误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有关,但我已经检查了它,似乎没有。

1 个答案:

答案 0 :(得分:8)

更改

$loader = new Loader\XmlFileLoader

$loader = new Loader\YamlFileLoader
DependencyInjection/AcmeFooExtension.php中的

。因为您正在加载yml文件。