1

我将 ZF2 与 Doctrine 一起使用,我想使用存储库,但出现此错误:

The class 'Application\Repository\EventRepository' was not found in the chain configured namespaces Application\Entity

实体:

namespace Application\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="Application\Repository\EventRepository")
 */
class Event {
    // ...
}

存储库:

namespace Application\Repository;

use Doctrine\ORM\EntityRepository;

class EventRepository extends EntityRepository
{
    public function test()
    {
        // ...
    }
}

在控制器中:

$this->getEntityManager()->getRepository('Application\Repository\EventRepository')->test()

在我的 module.config.php 中,我有这个:

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

所以我试图改变:

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

我有一个新错误:

Class "Application\Repository\EventRepository" sub class of "Doctrine\ORM\EntityRepository" is not a valid entity or mapped super class.

问题是什么?

谢谢

4

2 回答 2

0

检查此 自定义存储库您必须调用 $this->getEntityManager()->getRepository('Application\Entity\Event')->test()

于 2014-09-04T05:48:27.867 回答
0

是的,skurty,SylarBg是对的,而不是直接调用存储库,您需要调用相关实体,通过该实体将调用发送到存储库

于 2014-10-16T06:08:37.800 回答