Gradual Migration: Yii 2 in Parallel with Yii 1 on Same Site

We have a very large and complex application that uses Yii 1.x. We’re planning on moving to an Yii 2 backend with an Angular front end. So virtually all of our Yii 2 calls would return JSON objects only, and no views would be required.

It would be great if we could run the two versions of Yii in parallel, gradually replacing portions of the site as we can. We could use a URL distinction to switch between them. I think the only major issue would be sharing a session. Am I correct in that? Has anyone else done something like this? Any suggestions?

Thanks in advance.

Yes I have a large project based on Yii 1.1 that runs my clients back-offie. On the same server I also have their front-end, which includes a significant amount of e-commerce, using Yii2. The two environments share the same databases.

So from a technical standpoint there is absolutely no reason why you can’t run both environments on the same server. But it sounds like you want to take it a step further and be able to jump from one environment to the other using a shared session. One way to do this is to store your session information in the database. (See http://www.yiiframework.com/doc-2.0/yii-web-dbsession.html for an example in Yii2 for how to do this). Doing it this way would make it available to both environments.

Hope this helps!

  1. Sharing a session. Would require some work but overall not a huge problem because both Yii 1.1 and Yii 2.0 support custom session handlers.

  2. Serving different URLs with different endpoints. That’s about server config.

I’m just starting a similar project and have decided I have 2 choices.

Firstly, would be to try and integrate Yii1 into Yii2 so that i can occasionally call legacy code when required.

You’ve probably seen the wiki to integrate Yii2 into Yii1 (http://www.yiiframework.com/doc-2.0/guide-tutorial-yii-integration.html#) and there is also a forum post where you need to comment out thebootstrap logger.

So, it must be possible to do it the other-way round. To include Yii1 as a vendor in a Yii2 project ???

The alternative, is to convert the parts of legacy Yii1 code that I need from the new Yii2 frontend into a service and call these with either XHTML or JSON returns. This could be as simple as adding if (Yii::app()->request->isAjaxRequest) to controller actions …

This would then make me wonder if I could make my entire frontend website into an AJAX app …

Thanks to all for the ideas and suggestions. I wasn’t aware of any of the options mentioned so far! Looks like I’ve got some reading to do.