Step by step migration from Zend Framework 1 to 2

20,057

Solution 1

Migration from Zend Framework 1

This guide is intended to provide tools and strategies for migrating from Zend Framework 1 to Zend Framework 2. There is no single solution that will work for every project, nor any tools to automate the process.

In this guide, we will cover the following:

  1. Tools for namespacing your code.
  2. Tools for consuming Zend Framework 2 within your Zend Framework 1 application.
  3. Strategies for running Zend Framework 2 and Zend Framework 1 in parallel.
  4. Strategies for making your code easier to migrate, focussing primarily on clean separation of your domain logic and the MVC layer.
  5. Strategies for migrating the MVC layer.
  6. Strategies for migrating your domain layer.

http://framework.zend.com/manual/2.1/en/migration/overview.html

Solution 2

Somewhere it was once written that it will be easy peasy with some intermediate layer but I never saw any links or anything in the library that looked just remotely like it.

Now the only thing and latest information you can find is in the documentation's Overview page. It is this:

Note ZF2 is not backward compatible with ZF1, because of the new features in PHP 5.3+ implemented by the framework, and due to major rewrites of many components.

I never expected it to be backwards compatible but the key statement here I believe is the major rewrites of many components.

I've started a new project with ZF2 a few months ago where I only wanted the library; so no MVC which should be easy, right? So far it's been pretty much a nightmare because nothing is the same anymore. Besides some familiar class names or structures the whole framework has been completely rewritten from the ground up.

Things I loved, used a lot and knew by heart like forms, cache or session are completely different. For my project it has cost me a lot of time with no benefit. One of the key objects for ZF2 I thought was overhaul the documentation which is as of these written way worse than the previous one.

For my other existing ZF1.x projects I don't see how to manage an upgrade except to completely rewrite the application.

Solution 3

From the Zend Framework 2 FAQ:

I have an application built with Zend Framework 1 – will I be able to migrate it to the new version?

Absolutely. An important part of Zend Framework 2 is the migration layer that will allow ZF 1 code to run on the new ZF 2 engine, which will be made available in the future. With it, you will be able to add new ZF 2 code, and refactor existing code, at a controlled pace.

However, at this point, I have not heard of any actual migration layer. We can only hope there will be, but at this point, I have my doubts.

Solution 4

We have been migrating a large application from Zend Framework 1 to Zend Framework 2 over the past year. We started out with simple things like namespacing, and slowly worked our way into the various library components. Ultimately, we ended up editing Zend_Layout to work with Zend\Filter, Zend_Form to work with Zend\Filter and Zend\Json, Zend_Navigation to work with Zend\Permissions\Acl, etc. This helped us to eliminate almost all ZF1 components with the exception of the ZF1 application structure which includes four classes Zend_Application, Zend_Config, Zend_Controller, and Zend_Layout. The final piece of the puzzle is the implementation of Zend\Mvc\Application and Zend\View, the remainder is ZF2-ready.

Most recently, we created a proxy of sorts to hook into Zend\Mvc\Application and ZF2 modules from ZF1. This has been extremely helpful. I detailed the steps over at http://webjawns.com/2013/11/migrating-to-zf2-integrating-composer-and-doctrineormmodule/.

In summary...

  • Convert prefixes to namespaces (Model_ to Model\, Application_Controller to Application\Controller, etc.)
  • Replace non-MVC components with ZF2 counterparts including autoloader
  • Create ZF2 application structure and hooks to begin utilizing ZF2 modules
  • Move controllers and views (still working on a plan for this one)
Share:
20,057

Related videos on Youtube

aimfeld
Author by

aimfeld

Updated on July 09, 2022

Comments

  • aimfeld
    aimfeld almost 2 years

    I have to migrate an application from Zend Framework 1.12.0 to version 2. There seem to be no migration guides yet. I have already studied ZF2 coding conventions and I adopted dependency injection (Zend\Di) and PHP 5.3 namespaces. My goal is to refactor my ZF1 application into a ZF2 module.

    Question: Is it possible to proceed step-by-step with an at least partly working application after every step and avoid huge refactoring steps? If yes, what are the steps?

    Here's my idea of such a step-by-step migration, but I don't know if I end up with a working application after every step:

    1. Start by setting up the ZF2 Skeleton Application
    2. Set up a new module (MyApp) and reorganize the contents of my ZF1 application into the MyApp module folder structure. Then set up very basic configuration and bootstrapping and migrate the IndexController by extending it from the ZF2 AbstractActionController. The models (Zend_Db) and views (Zend_View) will be migrated later. The goal here is to have a working IndexController::indexAction which doesn't have many dependencies.
    3. Set up more configuration and bootstrapping (Routing, Translate, Locale, Cache, Db, Acl, ViewHelpers, ...). I'd like to set up the ZF1 versions of these components first and migrate them later one by one.
    4. Migrate the other controllers and set up dependency injection into the controllers either with Zend\Di or by using the ServiceManager.
    5. Set up automatic deployment by making the old phing scripts work with the new directory structure.
    6. Migrate the views (including helpers) and forms to ZF2.
    7. Migrate the models (from Zend_Db either to ZF2 Zend\Db or to Doctrine).
    8. Migrate other ZF1 components one by one (Translate, Locale, Cache, Acl, ...).
    9. Refactoring rehab and long holiday.

    However, I will have a workin application after every step only if certain ZF2 components work together with ZF1 components. I have no idea if it's e.g. possible to use ZF1 views (and view helpers) with ZF2 controllers.

    • Sam
      Sam over 11 years
      You can have in fact work ZF1 and ZF2 side by side, so smaller Steps are possible. The biggest problem is to reorganize your own project. I'd argue that a ZF1 App USUALLY is more than one Module. You pretty much have a good understanding thoug and your starting point is fine. Migrating is a tricky thing and usually ends up in refactoring pretty much everything :P
    • shadyyx
      shadyyx over 11 years
      Think of ZF2 as a whole new framework You want to migrate to. I'd bet You would need to rewrite whole Your application...
    • Andreas
      Andreas over 11 years
      Don't think that you will find a migration guide. I think you will have to rewrite your app for ZF2
    • petronic
      petronic about 11 years
      Not sure if you found it already, but here is explanation how to run ZF1 and ZF2 applications in parallel with some basic instructions for step by step migration from ZF1 to ZF2: framework.zend.com/manual/2.1/en/migration/…
    • aimfeld
      aimfeld over 8 years
      There is now a book on migrating from ZF1 to ZF2: phparch.com/books/zend-framework-migration-guide
  • Sam
    Sam over 11 years
    The main benefit of ZF2 is it's modularity. You do not have to rewrite everything as it was the case with ZF1. It has been an initial goal to provide a intermediate layer to migrate between ZF1 and ZF2, but currently this is not the case and quite frankly i doubt there will be.
  • Adrian World
    Adrian World over 11 years
    @Sam Don't know why you think ZF1 wasn't modular; it's a library as such it has to be modular. I rarely had to rewrite anything in ZF1. And the question by the OP is not about ZF2 vs ZF1
  • Sam
    Sam over 11 years
    I was commenting on your post and i wasn't making it a debate of ZF1 vs zf2 :) And with modular i was talking about zf1-applications - those are not modular. The framework itself is to a high degree ;)
  • electblake
    electblake almost 11 years
    I haven't done it myself (yet) but at least it's from official source. If I finish it (successfully) I'll update this.