Rub*_*ech -2 service symfony doctrine-orm
你能给我建议一个解决方案,如何从 Symfony 3 中的服务访问 Doctrine?我将 Doctrine 对象从 Controller 发送到构造函数中创建的 Service 对象,但我不确定它是否是最佳选择。
你能给我推荐一个更好的解决方案吗?
public function editGroupAction($groupId) {
$doctrine = $this->getDoctrine();
$roleHelper = new RoleHelper($doctrine);
}
Run Code Online (Sandbox Code Playgroud)
小智 5
你可以像这样注入它:
use Doctrine\ORM\EntityManagerInterface;
private $em;
public function __construct(EntityManagerInterface $entityManager) {
$this->em = $entityManager;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
108 次 |
| 最近记录: |