migration from zend framework to phalcon

Dear all,

I want to switch from zend framework to phalcon. Now, I've several questions how to migrate.

Anybody knows a migration best practice documantation, or just an phalcon book?

How do I create View-Helper, Controller-Helper with using templates? Is it possible to use $view->partial() without echo or should I do it like this:

ob_start();
$this->view->partial('layouts/navigation', 
  array(
    'navigation' => $navigation,
    'breadcrumb' => $breadcrumb
  ));
$result = ob_get_contents();
ob_end_clean(); 

We don't use "normal" models, because we've a abstract-backend-database-layer. What is the best base-class to use (extend) with this special kind of models?

Can i use \Phalcon\DI for Zend_Registry or should i use something different?

Thank you a lot for your help and tips.

Im on my phone i cant answer well here but in tje morning (now its night here) i will post my experoence migrating from zend+doctrine to phalcon



1.6k

This sounds great!

edited Oct '14

In your Bootstrap you can create helper (not matters Controller-Helper or View-Helper .. ):

$di->set('helper', new \Application\Mvc\Helper());

Helper class:

namespace Application\Mvc;

class Helper
{

    // Simple translate helper
    public function translate($string)
    {
        $t = \Phalcon\DI::getDefault()->get('translate');
        return $t->_($string);

    }

    // Put your helpers here...

}

Then, enywhere (Controller, View ... it just must extends \Phalcon\DI\Injectable) you can use this:

echo $this->helper->translate('Hello world!');

Good luck ;)

edited Oct '14

Well, we use to use zend + doctrine for our projects but when we know phalcon it was in a poit wich starts to be 'useful' for a big application, i mean to simplify migrating our code without writing things, or have a good to use documentation. The problem was the project grows very fast and when we have time to migrate to phalcon all the api was old (0.5) -> (0.9). At the point we start the process we had abot the 30% of the whole project already in production. It was a bit risked, but exciting.

Mainly there are to ways to do this, first is to mantain the Zend full-stack and make secure-phalcon changes. Second One is to write a phalcon full-stack and make a bridge for the old zend code. Rewrite everything was not a option for us.

We focused all the time in rewrite the less code, cause we are in production they need new-features, bug correction and we dont want to write zend and phalcon. In the other hand we cnt go out production to migrate so we start to make compatibilty bridges, staying on the Zend-Side.

Starting we dont use views in zend, cause our application is a set of json-apis and we use angular JS in front end so the easiest thing to translate was controllers, every application is different, so you need to find the easiest/quickest part of your application to translate. One important thing, if you follow good MVC dont touch your models now, cause is mainly business-logic center.

We start modifying the index.php adding a di - factoryDefault constructor, then leaving all zend components away rewriting / adapting to phalcon-di nice components, identify what do you use the most, and what can be easily replaced dont write more than you need , but allways leave space for it .. you'll need it :), so it comes the funny part we made an adapter for controllers from Zend to Phalcon it allows us to change smooothly the code. Zend allows to trap the undefined actions by __call magic, by doing something like this you will gain time.

public function __call( $notdefinedAction )
{
   //Instantiate PhalconControllers
   //Setting di 

   //Call application

   die();
}

I think this part will go slower for you cause you use views and helpers, i can suggest try translate all and use Volt instead of injecting on volt the other services (So you can leave zend faster). You have more time than before, cause you are in a stable point, translate all controllers. And enjoy this part its a really nice moment when you are free from zend. Note than the controllers are very nice to translate cause models/request/responses are a similar api, but i dont know the helpers, the previous suggestion looks good.

When we finish to translate controllers, and view replace our bootstrap (index.php) files so we can point naturally Phalcon to our Phalcon pretty new controllers and we put a Doctrine loader on it. We forgot to replace a Rpc Module, when analize where used it we found only two cases, i write a controller for this cases and route specially, instead of importing from Zend, cause I found Zend too-coupled it needs a lot of Classes to work, so i rewrite it. And at this point we has all application (Except models) in Phalcon, Today we use phalcon and docttine models, Phalcon in new Modules, doctrine in old ones. And the application is faster and more mantainabily than zend one. =)

Great answer there with good pointers, I'm just now figuring out this exact migration zend 1 + doctrine 2 to, hopefully, Phalcon 3 and PHP 7. I think you had a good point there to integrate Phalcon gradually, starting from bootstrap all the way up.