2016-05-17 7 views
2

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がエンティティの一時リポジトリファイルを作成するようにしましたか?

ありがとうございます!

+0

'$ this-> get( 'myRepositoryService')'が 'AppBundle \ Entity \ MyRepository'のインスタンスであることを確認しましたか?また、エンティティのマッピングで 'repositoryClass'をこのクラスに設定しましたか? –

+0

@dragosteこのエンティティの 'repositoryClass'を設定するのを忘れました。 * facepalm *答えとして投稿してください、私はそれを受け入れるでしょう。どうもありがとう! –

+1

私はそれについて数回も忘れました。 ;-) –

答えて

2

コードはsymfonyの3.0に私のために働いて、次のとおりです。

some_repository: 
    class: AppBundle\Repository\SomeRepository 
    factory: ['@doctrine.orm.default_entity_manager', getRepository] 
    arguments: [AppBundle:SomeEntity] 

あなたの工場のサービス名とは異なるとファクトリメソッドとエンティティ名には単一引用符が存在しないことに注意してください。

私のコメントで言及したように、repositoryClassがエンティティのマッピングに設定されている必要があります。

+0

コロンで文字列をクォートする方が良いです - 'arguments:['AppBundle:SomeEntity']' – luchaninov

関連する問題