Symfony2: How to access to service from repository

后端 未结 8 1712
有刺的猬
有刺的猬 2020-12-31 13:08

I have class ModelsRepository:

class ModelsRepository extends EntityRepository
{}

And service

container_data:
 class:               


        
8条回答
  •  無奈伤痛
    2020-12-31 14:05

    Are you sure that is a good idea to access service from repo?

    Repositories are designed for custom SQL where, in case of doctrine, doctrine can help you with find(),findOne(),findBy(), [...] "magic" methods.

    Take into account to inject your service where you use your repo and, if you need some parameters, pass it directly to repo's method.

提交回复
热议问题