最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Symfony2 在service中如何使用Doctrine
时间:2022-06-25 02:49:29 编辑:袖梨 来源:一聚教程网
在service中有个方法需要调用Doctrine,使用
| 代码如下 | 复制代码 |
| $user = $this->getDoctrine()->getRepository('AtotrukisMainBundle:User') |
|
提示"getDoctrine"找不到,那么我们应该怎么做呢?
解决方法:
第一步:
在service配置文件中添加arguments
| 代码如下 | 复制代码 |
|
eventService: class: Atotrukis\MainBundle\Service\EventService arguments: ["@doctrine.orm.entity_manager"] |
|
第二步:
在service对应的class:Atotrukis\MainBundle\Service\EventService中增加如下代码:
| 代码如下 | 复制代码 |
|
protected $em; public function __construct($em) { $this->em = $em; } |
|