Inject dependencies into Doctrine2 Model via Silex/Pimple
-
11-02-2021 - |
Question
is there any way to inject dependencies into Doctrine2 models with Silex? Since the models are not constructed manually i can't pass anything to the constructor and i can't find a tutorial how to do it. I already browsed the source of Silex and Pimple and i didn't got how this could be archived. Any help appreciated.
Nils
Update: Models are newable not injectable so you need to inject dependencies via setters after construction. doctrine2 implements this feature out of the box, so here is a link to the documentation:
http://www.doctrine-project.org/docs/orm/2.1/en/reference/events.html
Solution
Silex doesn't have built-in service provider for Doctrine 2 ORM, but you can use this extension.
I posted on my blog a short tutorial how to implement it to Silex.
OTHER TIPS
There is only a Doctrine DBAL. An ORM service is not supplied.
source: http://silex.sensiolabs.org/doc/providers/doctrine.html
Did you create your own service for doctrine ORM?