我从 Symfony 2.7 升级到 3.0。几乎可以用了。只有问题:我无法覆盖下面代码中的AppBundle\Entity\MyRepository
,该文件甚至不是必需的(我将其重命名为用于测试) 并被 Symfony 跳过。
app/config/services.yml
# old, 2.7 (worked):
myRepositoryService:
class: AppBundle\Entity\MyRepository
factory_service: doctrine.orm.entity_manager
factory_method: getRepository
arguments: [AppBundle\Entity\MyEntity]
# new, 3.0 (skips the MyRepository):
myRepositoryService:
class: AppBundle\Entity\MyRepository
factory: ['@doctrine.orm.entity_manager', 'getRepository']
arguments: ['AppBundle\Entity\MyEntity']
AppBundle\Entity\MyRepository
class MyRepository extends EntityRepository {
public function findAll() {
die("MyRepository->findAll()"); // not executed
}
}
AppBundle\Controller\MyController.php
$myItems = $this->get('myRepositoryService')->findAll(); // should die but doesn't
我是否错误配置了我的 services.yml 以便 Symfony 为实体创建临时存储库文件而不是使用我创建的文件?
提前致谢!
最佳答案
以下代码在 Symfony 3.0 中适用于我:
some_repository:
class: AppBundle\Repository\SomeRepository
factory: ['@doctrine.orm.default_entity_manager', getRepository]
arguments: [AppBundle:SomeEntity]
请注意与您的工厂服务名称不同,并且工厂方法和实体名称没有单引号。
正如我在评论中提到的,实体映射中应该设置 repositoryClass
。
关于php - 交响乐团 3 : can't overwrite repository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37277145/