Rigor Guild
Published in

Rigor Guild

Yii2 & Doctrine ORM simple integration

https://unsplash.com/photos/IKHvOlZFCOg

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 src/Infrastructure/Persistence/doctrine-mappings

We’ve added a new file di.php into standard Yii2 config folder

Then it’s really easy to reuse this configuration into theweb.php or console.php files.

Example web.php file

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!

--

--

--

Today, still wanted by the government they survive as soldiers of fortune. If you have a problem, if no one else can help, and if you can find them… maybe you can hire the Rigor Guild Team!

Recommended from Medium

Managed Delivery: Evolving Continuous Delivery at Netflix

Government Data in the Public Cloud

Diary of a Coding Kid. Day 16

6 tips to improve cloud storage user adoption

Java List Benchmarks

The Future of Distro Delves

Backing up Dotfiles with the InterPlanetary File System (IPFS) or How to Slice Bread with a…

Magento 2 PWA in 5 minutes without re-platforming. Real use case.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Christian Soronellas

Christian Soronellas

XP Practitioner — Author of https://leanpub.com/ddd-in-php

More from Medium

How to Clone Laravel Project from Git Repository and Run it on Local Machine

How To Enable PHP Debugging with XDebug and Visual Studio Code (Windows and Xampp)

Greppy: A Lightweight Perl/PHP Website Search Engine Based on Grep

GNU Grep

A simple PHP site (4/?)— Routing