|
1
|
| Trevor Donahue · 技术社区 · 12 年前 |
|
|
1
1
如果CoreBundle UserController从未通过HTTP访问,其方法也不会返回Symfony\Component\HttpFoundation\Response的实例,那么它就不是真正的控制器。 您应该更好地将其定义为服务,如在CoreBundle\service\User中,并通过DI容器注入EntityManager。 服务.yml
然后,它将从Acme\Bundle\APIBundle\Controller\UserController提供,包括以下内容:
当然,您也可以将Acme\Bundle\APIBundle\Controller\UserController定义为一个单独的服务,然后注入“corebundle.userservice”,以方便使用。 我建议你阅读Symfony的文档 Dependency Injection . |