如何在ZF2中配置Doctrine文件映射驱动程序

Bel*_*los 4 php doctrine-orm zend-framework2

我有这个错误:

致命错误:未捕获的异常'Doctrine\Common\Persistence\Mapping\MappingException'及消息'文件映射驱动程序必须具有有效的目录路径,但是给定路径[path/to/my/entities]似乎不正确

我在我的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'
            )
        )
    )
)
Run Code Online (Sandbox Code Playgroud)

Osk*_*kar 8

我有完全相同的问题.我通过Entity在doctrine期望我存储我的实体的位置创建一个空目录来解决它.您所要做的就是在以下位置创建一个空Entity目录: __DIR__ . '/../src/Realez/Entity'.


Ron*_*tel 1

修改您的 module.config.php 文件。

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'
                ),
            ),
        ),
    ),                 
);
Run Code Online (Sandbox Code Playgroud)