How to upgrade Yii 1.x to Yii 2.0

11,528

The Yii2 guide has excellent documentation in this regard see Upgrade from v1

I recently migrated couple of moderately complex applications from Yii 1.x to Yii 2.0. There are two ways to go about it , either you can run Yii 1.x and Yii 2 at the same time see using-yii-2-with-yii-1. Then migrate part by part, while it is possible it was quite bit of pain, like trying to rebuild the second floor while living on the third.

Alternatively you can rewrite the entire application bottom up with the exact same functionality, I found this to be much more efficient, significant code could be reused with only minor modifications, also that gave opportunity to tweak the design without changing functionality.

The important thing is to ensure the exposed API ( i.e. the frontend / UI / functionality) remains the same. It is always tempting to update functionality or change features during a rewrite, however if you stick to strictly reimplementing everything for Yii2 then consider changing your API, your migration will be smoother.

Share:
11,528
Pawan Shukla
Author by

Pawan Shukla

Updated on June 11, 2022

Comments

  • Pawan Shukla
    Pawan Shukla almost 2 years

    How to upgrade Yii 1.x version to Yii 2.0 latest release version? I am using ubuntu OS , Process to updating my old Yii to new Yii release version 2.0?

  • Dan Ray
    Dan Ray about 7 years
    Would it be possible for you eyeball the time to do a rewrite based on existing Yii 1 code, relative to the time it took to build initially? Do you think it's 1/3 the time? 3/4?
  • Manquer
    Manquer about 7 years
    it really depends on how well your Yii 1 application is written, whether it is well designed fat models and thin controllers, proper separation of concerns etc, if you do just rewrite, it should be doable in less than half the original time, assuming the layouts and UI will be same.
  • dkellner
    dkellner about 4 years
    We're doing it right now, with a slightly different approach. In a few months I'm gonna report how it turned out to be a lot of pain or not, but the concept behind is an intermediate class (we call it Yang) that mimics the behaviour of Yii1, acting simply as a wrapper around its calls, and then we bridge the differences to Yii2 within this one class. Again, not sure this will work out perfectly but it's the best we could come up with to keep the production versions running while going forward with Yii2 testing & reduce git divergence from the project backbone.