Beltran Moreno Carlos
Beltran Moreno Carlos

Reputation: 51

How to configure Doctrine file mapping driver in ZF2

I have this error:

Fatal error: Uncaught exception 'Doctrine\Common\Persistence\Mapping\MappingException' with message 'File mapping drivers must have a valid directory path, however the given path [path/to/my/entities] seems to be incorrect

and i have this in my module.config.php:

'doctrine' => array(
    'driver' => array(
        // defines an annotation driver with two paths, and names it `my_annotation_driver`
        'my_annotation_driver' => array(
            'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            'paths' => array(
                __DIR__ . '/../src/Realez/Entity',
                'another/path'
            ),
        ),

        // default metadata driver, aggregates all other drivers into a single one.
        // Override `orm_default` only if you know what you're doing
        'orm_default' => array(
            'drivers' => array(
                // register `my_annotation_driver` for any entity under namespace `My\Namespace`
                'Realez/Entity' => 'my_annotation_driver'
            )
        )
    )
)

Upvotes: 5

Views: 9346

Answers (4)

takeshin
takeshin

Reputation: 50638

Ensure your paths are correct.

           __NAMESPACE__ . '_driver' => [
                'class' => AnnotationDriver::class,
                'cache' => 'array',
                'paths' => [__DIR__ . '/../src/Entity/'], 
// or:                'paths' => [__DIR__ . '/../src/Entity/'.__NAMESPACE__.'/Entity']

            ],
            'orm_default' => [
                'drivers' => [
                    __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
                ]
            ],

Also you may try clearing metadata cache with doctrine command line tool:

./doctrine-module orm:clear-cache:metadata

Upvotes: 0

Abhinav bhardwaj
Abhinav bhardwaj

Reputation: 2737

**File mapping drivers must have a valid directory path, however the given path [path/to/my/entities]** 

this mean you don't have an Entity folder at that directory

You just need to create one at that location

Upvotes: 1

Oskar
Oskar

Reputation: 2562

I had exactly the same problem. I solved it by creating an empty Entity directory in the location where doctrine expect me to store my entities. All you have to do is create in following location an empty Entity directory: __DIR__ . '/../src/Realez/Entity'.

Upvotes: 8

Ronak Patel
Ronak Patel

Reputation: 390

Modify your module.config.php file.

return array(
    'doctrine' => array(
        'driver' => array(
            __NAMESPACE__.'_driver' => array(
                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/'.__NAMESPACE__.'/Entity')
            ),
            'orm_default' => array(
                'drivers' => array(
                     __NAMESPACE__'\Entity' =>  __NAMESPACE__.'_driver'
                ),
            ),
        ),
    ),                 
);

Upvotes: 1

Related Questions