2

Mybundle 已经设置为使用 services.yml

但我想使用 services.xml。

所以我改变了 DependacyInjection/MybundleExtension.php

#$loader->load('services.yml');     
$loader->load('services.xml');

但它说

Unable to parse in      "\/Users\/whitebear\/httproot\/mutor\/src\/Acme\/MyBundle\/DependencyInjection\/..\/Resources\/config\/services.xml" at line 1 (near "").

我的 services.xml 在这里,我认为它是正确的(只是从其他站点复制和粘贴)

<services>
    <service id="acme.demobundle.calendar_listener" class="Acme\DemoBundle\EventListener\CalendarEventListener">
        <argument type="service" id="doctrine.orm.entity_manager" />
        <tag name="kernel.event_listener" event="calendar.load_events" method="loadEvents" />
    </service>

</services>

我还有其他地方需要改变吗?

4

1 回答 1

5

你用XmlFileLoader吗?

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

标准 xml 结构也包括container标签

<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <parameters>
        ...
    </parameters>

    <services>
        <service id="...">
        </service>
    </services>
</container>
于 2013-06-10T04:49:21.327 回答