I'm using ZF2 with Doctrine and I would like to use a repository but I've this error:
The class 'Application\Repository\EventRepository' was not found in the chain configured namespaces Application\Entity
The entity:
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="Application\Repository\EventRepository")
*/
class Event {
// ...
}
The repository:
namespace Application\Repository;
use Doctrine\ORM\EntityRepository;
class EventRepository extends EntityRepository
{
public function test()
{
// ...
}
}
In the controller:
$this->getEntityManager()->getRepository('Application\Repository\EventRepository')->test()
In my module.config.php, I've this:
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'
)
)
),
// ...
)
);
So I tried to change for:
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'
)
)
),
// ...
)
);
And I've a new error:
Class "Application\Repository\EventRepository" sub class of "Doctrine\ORM\EntityRepository" is not a valid entity or mapped super class.
What is the problem?
Thank you
Check this Custom Repositories You must invoke $this->getEntityManager()->getRepository('Application\Entity\Event')->test()