标签云

微信群

扫码加入我们

WeChat QR Code

I try to create a class to manage some part of my appbut I need to access the configuration in resources/config.ymlI tryed to extends my class with containerAware as a controlerBut he container is not set...I would like to be able to do something like that:class MyClass extends ContainerAware{ public function myFunciton() {$em = $this->get('Doctrine')->getEntityManager(); }}any suggestion is welcome


My suggestion is to study carefully the section on Services in the reference manual. Services Once you have walked through the process then it becomes trivial to inject the entity manager into MyClass.

2019年04月20日01分40秒

Thanks for the quick answer!

2019年04月20日01分40秒

Does this work for the entity? Like to be able to self save the entity? ex: $entity->save()

2019年04月20日01分40秒

No. Entities are plain PHP objects. They have no knowledge of the entity manager, nor should they. You're thinking of the Active Record pattern from Doctrine 1. Doctrine 2 uses the Data Mapper pattern.

2019年04月19日01分40秒