Migrate code from zend to yii

We have system written in zend framework and we want migrate all code to Yii.

But there are one big problem: system is currently in active use and I need develop new features every day, so I can’t stop programming for a while and migrate all code to Yii

Hardest task would be rewrite all Zend DB classes, so I wanted to ask, is there is possible to use Zend_DB component in Yii together with Yii Model? In that case I could use old Zend DB and rewrite step by step all DB queries from Zend_DB to Yii Model.

Models are really deeply involved in Yii structure, I’d better duplicate the model classes when developing new features in Yii.

Just for sake of curiosity: why did you choose to port from Zend to Yii?

In beggining I will use only Yii DAO because there are to complex queries for models, so it wouldn’t be a problem.

I am creating one other project with Yii and I am suprised about how easy is to create web apps with Yii :)

Well, The best would to rewrite code from scratch, I don’t think you can easy use models from Zend Framework. In Yii it is very easy to import 3rd party components, especially from Zend Framework. I think that with some extensions, you would be able to use Zend Models, but it could take you much time, you will not be able to use gii tool(for crud, models), so, if you can not afford time to rewrite it from scratch, I wouldn’t try to do it this way.

Yes, with Yii it is easy to create web applications, and funny in comparation with development using Zend Framework, and both are very good frameworks.

Main problem is that I need connect to data base both with Zend_DB and with Yii DAO. I need only get data - I will not use yii models in beggining.

For example in Yii Controller class


$zendModel = new ZendModelCategory();

$data  = $zendModel->getAll();


$yiiModel = new Category();

$yiiModel->getAllWithDAO();

Model classes:




class ZendModelCategory extends Zend_Db_Table_Abstract{

    function getAll(){

        $db=$this->getAdapter();

	$st =  $db->query('SELECT * FROM category');

	return $st->fetchAll();

    }

}


class Category extends CActiveRecord{

   function getAllWithDAO(){

       $cmd = $this->dbConnection->createCommand("

            SELECT * FROM category

            ");

        return $cmd->queryAll();

   }

}



$zendModel->getAll() and $yiiModel->getAllWithDAO() will return the same data, so I can firstly rewrite all Controller classes from zend to yii so that it will use old zend classes for db operations and after that I will rewrite all zend model classes to yii dao, so that new yii model classes will return same data as old zend model classes. After that I will have my current zend code what will work in yii, but without yii model features. And only then I can start using yii model features in some cases where it is appropriate.

An advice, spend a bit of time for learn how to use efficelty models, expecially for create/update pourpouses.

I did some refactor work on lot of projects that didn’t use models as basement, and they were really bad written.

Models are cool and helps you keeping code clean, use them even if they looks complicated.

I agree, you want to be making use of the ActiveRecord models if you’re moving to Yii. I can however see why you want to make use of the DAO stuff during the migration. I would probably approach it similarly though:

[list=1]

[*]Migrate controller code keeping Zend models.

[*]Create AR versions of the Zend models (create unit tests)

[*]Update controllers to make use of AR querying, you can always remap the objects into the array of arrays that Zend gives you using a helper class.

[*]Update the views to make use of the AR models.

[/list]

I have a question, can a magento store shopping cart website based on zend framework be migrated into a new Yii framework website instead of using zend and writing all the code again from scratch????

Thanks.