How to inject a repository into a service in Symfony?

前端 未结 5 1636
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 21:39

I need to inject two objects into ImageService. One of them is an instance of Repository/ImageRepository, which I get like this:

$         


        
5条回答
  •  半阙折子戏
    2020-11-30 22:23

    In case if do not want to define each repository as a service, starting from version 2.4 you can do following, (default is a name of the entity manager):

    @=service('doctrine.orm.default_entity_manager').getRepository('MycompanyMainBundle:Image')
    

提交回复
热议问题