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

时间:2013-09-12 17:51:58

标签: 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'
            )
        )
    )
)

4 个答案:

答案 0 :(得分:8)

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

答案 1 :(得分: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'
                ),
            ),
        ),
    ),                 
);

答案 2 :(得分:1)

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

这意味着您在该目录中没有实体文件夹

您只需在该位置创建一个

答案 3 :(得分:0)

确保paths正确无误。

           __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'
                ]
            ],

您也可以尝试使用doctrine命令行工具清除元数据缓存:

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