I を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 *答えとして投稿してください、私はそれを受け入れるでしょう。どうもありがとう! –
私はそれについて数回も忘れました。 ;-) –