【发布时间】:2016-05-17 13:09:41
【问题描述】:
我从 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 为实体创建了一个临时存储库文件,而不是使用我创建的文件?
提前致谢!
【问题讨论】:
-
您检查过
$this->get('myRepositoryService')是否是AppBundle\Entity\MyRepository的实例吗?您是否在实体映射中将repositoryClass设置为此类? -
@dragoste 我忘了为这个实体设置
repositoryClass。 facepalm 请将其发布为答案,我会接受。非常感谢! -
我也忘记了几次。 ;-)
标签: php dependency-injection symfony