2017-03-02 2 views
0

既存のDIコンテナが自動的に挿入されるようにサービスを設定する必要があります。それは代わりにContainerAwareInterfaceを実装し、callブロックを使用して実際の噴射を設定する必要がありますので、私のContentQueryクラスはすでに、別のクラスをextendsSymfony DIコンテナ自体をサービスに挿入するにはどうすればよいですか?

<services> 
    <service id="my_module.model.content_query" class="MyModule\Model\ContentQuery"> 
    <call method="setContainer"> 
     <argument type="service" id="container" /> 
    </call> 
    </service> 
</services> 

問題は、私はXMLでコンテナ自身を識別する方法がわからないということです。上記の設定を使用して、私はこのエラーを取得する:

the service "my_module.model.content_query" has a dependency on a non-existent service "container"

は、私はむしろちょうど私が、私はかなり簡単に見つけ出すことができると思いた、PHPでこれを行うだろうが、XMLを使用するという決定は、この時点で私の手の外にあります。コンテナインスタンスをサービスとして識別する方法はありますか?

答えて

0

Welp。投稿後約1分私はそれを理解した。

<services> 
    <service id="my_module.model.content_query" class="MyModule\Model\ContentQuery"> 
    <call method="setContainer"> 
     <argument type="service" id="service_container" /> 
    </call> 
    </service> 
</services> 
+2

アプリ/コンソールデバッグ:コンテナはあなたの友達です:ちょうどid="service_container"だけではなく "コンテナ" を指定するために必要なP

Cerad

関連する問題