我升级从Symfony 2.7到3.0。它几乎工作。只有问题:我不能在下面的代码中覆盖AppBundle\Entity\MyRepository
,该文件甚至没有必要(我将其重命名为测试)并被Symfony跳过。Symfony 3:无法覆盖存储库
应用/配置/ 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 \实体\ MyRepository
class MyRepository extends EntityRepository {
public function findAll() {
die("MyRepository->findAll()"); // not executed
}
}
的appbundle \控制器\ 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 *请将它作为答案发布,我会接受它。非常感谢! –
我也忘了那几次。 ;-) –