ACNB
ACNB

Reputation: 846

YamlDriver for Doctrine2 in Zend2

I'm using the DoctrineORMModule to integrate Doctrine2 with Zend2. Everything works just fine when I'm using the AnnotationDriver as described in various examples. However, I cannot get the YamlDriver to work. In my module.config.php I tried:

'doctrine' => array(
    'driver' => array(
        'ApplicationDriver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/Application/Entity')
        ), 
        'YamlDriver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\YamlDriver',
            'cache' => 'array',
            'extension' => '.dcm.yml',
            'paths' => array(__DIR__ . '/../src/Application/Mapping')
        ),

        'orm_default' => array(
            'drivers' => array(
                'Application\Entity' => 'ApplicationDriver',
                'Application\Mapping' => 'YamlDriver'
            )
        )
    )
)

However, the EntityManager cannot find my classes. Cam you give me a working example of how to use yaml with doctrine2 and zend2?

Upvotes: 2

Views: 731

Answers (1)

Ocramius
Ocramius

Reputation: 25431

I assume your entities are in namespace Application\Entity: this means your driver should be assigned for that namespace as in following example:

'doctrine' => array(
    'driver' => array(
        'MyYamlDriver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\YamlDriver',
            'cache' => 'array',
            'extension' => '.dcm.yml',
            'paths' => array(__DIR__ . '/mappings')
        ),

        'orm_default' => array(
            'drivers' => array(
                'Application\Entity' => 'MyYamlDriver',
            )
        )
    )
)

Basically, the configuration maps a particular named driver to a namespace that you want to use. In this case, MyYamlDriver is assigned to handle any mapping for the namespace Application\Entity

Upvotes: 3

Related Questions