According to your code, you already have an EntityManager
injected. You don't need to call $em = $this->get('doctrine')->getEntityManager()
— just use $this->em
.
If you don't inject an EntityManager
already, read this.
UPDATE:
You need to make the container inject an EntityManager
into your service. Here's an example of doing it in config.yml
:
services:
your.service:
class: YourVendorYourBundleServiceYourService
arguments: [ @doctrine.orm.entity_manager ]
I prefer to define bundles' services in their own services.yml
files, but that's a bit more advanced, so using config.yml
is good enough to get started.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…