我将 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.
问题是什么?
谢谢