1

I am trying to build an eventlistener for my project and followed the instruction of this guide: How to register eventlisteners I edited my services.xml like in the tutorial , but i get this error message, when i want to test it:

InvalidArgumentException: There is no extension able to load the configuration for "doctrine:config" (in /var/www/symfony/src/Acme/AppBundle/DependencyInjection/../Resources/config/services.xml). Looked for namespace "http://symfony.com/schema/dic/doctrine", found none

My services.xml :

    <?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
    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">



    <doctrine:config>
        <doctrine:dbal default-connection="default">
            <doctrine:connection driver="pdo_sqlite" memory="true" />
        </doctrine:dbal>
    </doctrine:config>

    <services>
        <service id="my.listener" class="Acme\AppBundle\EventListener\Confirmer">
            <tag name="doctrine.event_listener" event="preUpdate" />
        </service>

    </services> 

</container>

Where is the problem?

ChrisS
  • 736
  • 2
  • 8
  • 21
  • do i have to change any config to use a services.yml ? – ChrisS Jul 17 '13 at 16:25
  • The Symfony [guide](http://symfony.com/doc/2.2/cookbook/doctrine/event_listeners_subscribers.html) displays each configuration sections in three languages: YAML, XML and PHP. You can switch between them using the tabs at the top. YAML is the default. – Alessandro Desantis Jul 17 '13 at 16:27
  • YAML isn't the default for service configuration, almost all of the widely used bundles out there use XMl ... for a good reason - XML provides better autocompletion and validation options. The IDE integration for XML files can provide you easier coding than YAML especially with Emmet or ZenCoding involved. – Nicolai Fröhlich Jul 17 '13 at 18:32
  • The symfony standard edition already comes with a preconfigured doctrine connection. see my answer below. – Nicolai Fröhlich Jul 17 '13 at 18:37

1 Answers1

1

You don't need the doctrine configuration in your service config.

The connection driver is being configured inside app/config/config.yml. The listener configuration looks good though - just remove the doctrine:config stuff.

Have a look at the doctrine configuration reference.

Symfony will automatically use the default connection for your listener/subscriber if you don't specify one using the connectionoption. The documentation is a bit confusing here but the doctrine connection is just there to show how to use a different connection.

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130