条令和ZF2的自定义存储库



我正在使用带有条令的ZF2,我想使用一个存储库,但我有这个错误:

The class 'ApplicationRepositoryEventRepository' was not found in the chain configured namespaces ApplicationEntity

实体:

namespace ApplicationEntity;
use DoctrineORMMapping as ORM;
/**
 * @ORMEntity(repositoryClass="ApplicationRepositoryEventRepository")
 */
class Event {
    // ...
}

存储库:

namespace ApplicationRepository;
use DoctrineORMEntityRepository;
class EventRepository extends EntityRepository
{
    public function test()
    {
        // ...
    }
}

在控制器中:

$this->getEntityManager()->getRepository('ApplicationRepositoryEventRepository')->test()

在我的module.config.php中,我有以下内容:

return array(
    // ...
    'doctrine' => array(
        'driver' => array(
            'application_entities' => array(
                'class' => 'DoctrineORMMappingDriverAnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/Application/Entity')
            ),
            'orm_default' => array(
                'drivers' => array(
                    'ApplicationEntity' => 'application_entities'
                )
            )
        ),
        // ...
    )
);

所以我试着换成:

return array(
    // ...
    'doctrine' => array(
        'driver' => array(
        'application_entities' => array(
            'class' => 'DoctrineORMMappingDriverAnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/Application/Entity')
        ),
        'application_repositories' => array(
            'class' => 'DoctrineORMMappingDriverAnnotationDriver',
            'cache' => 'array',
            'paths' => array(__DIR__ . '/../src/Application/Repository')
        ),
        'orm_default' => array(
            'drivers' => array(
                'ApplicationEntity'     => 'application_entities',
                'ApplicationRepository' => 'application_repositories'
            )
        )
    ),
        // ...
    )
);

我有一个新错误:

Class "ApplicationRepositoryEventRepository" sub class of "DoctrineORMEntityRepository" is not a valid entity or mapped super class.

问题出在哪里?

感谢

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

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

相关内容

  • 没有找到相关文章

最新更新