Yii2 & Doctrine ORM simple integration
This all comes from a consultancy we’re currently doing. Our client need, as a stepping-stone towards more modern architecture and a more modern software stack, to integrate Doctrine ORM into their current Yii2 installation. We found some extensions: Yii2-Doctrine and Doctrine2Orm but after examining them further, they don’t seem like a good fit. Mainly for the lack of maintenance of both of them. In fact, they don’t currently have active development anymore.
Therefore, we started digging into Yii2 documentation trying to find the most simple way to integrate both of them. And this is what we achieved.
Yii2 Dependency Injection for the win
Although compared to other frameworks like Symfony or Laravel it’s a bit simpler, yet Yii2 Dependency Injection has enough features to integrate Doctrine ORM in a straightforward way. All the Doctrine ORM entities should be placed in a
/src/DomainModel folder and all the XML mapping files should be placed in a
Then it’s really easy to reuse this configuration into the
And then from a controller
The full source code can be found at https://github.com/rigorguild/yii2-doctrine.
This is one of the cases we help with. If you need help on how to take on your technical challenges, we can surely help. Don’t hesitate to contact us!