Yii to Phalcon migration

Hello all!!

Could you please help - I have a project written with Yii... What would be the easiest and\or fastest way to migrate it from Yii to Phalcon??

Thank you!

I would suggest making a list of what you have:

  • Any models you are using
  • Controllers and views. Views made in twig might need a little bit of tweaking
  • Routing
  • Configuration
  • etc etc

Once you have a full list prioritize by controller and start building the basics. I think this the easiest way to approach the conversion.

You can start by downloading the Phalcon dev tools and creating a skeleton project, then work your way up from there.

Hope this is a little bit helpful to you.



2.4k
edited Mar '14

Thank you Stephen!

We have got a set of functions in Yii, that shall be rewritten to Phalcon. For instance, this one http://s020.radikal.ru/i720/1403/b7/5372335eef95.png My vision is that we can rename some Yii calls and rename them to ones existing in Phalcon which do the same things.

How do you think, is it possible to translate such code to Phalcon? I mean, Does Phalcon have similar classes like in Yii? Or they completely different and I shall write functions from scratch?

edited May '15

I don't know if it's a little to late to answer to you, but for reference of other readers may be helpful:

I'm migrating an application poorly developed in Zend Framework 1 to Phalcon. My approach is to keep both frameworks working at the same time during the migration, so we can make progress in little steps rather than a big rewrite.

So what I did is: I renamed the index.php of the zend application to zend_app.php and created an special .htaccess file that serves the request to phalcon.

In phalcon, if the controller/action is not found, we redirect to the same request adding a get variable (zfb, for Zend FallBack), so the .htaccess detects that variable and forwards the request to the zend application.

Better seen than explained, here you have my .htaccess file: RewriteEngine On

Options -Indexes

AddDefaultCharset UTF-8
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteCond %{QUERY_STRING} !(^|&)zfb=
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]

RewriteRule ^.*$ zend_app.php [NC,L]

And here is my "not found" action

public function fallBackToZendAction()
{
    $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);
    $uri = Di::getDefault()->get('request')->getURI();
    if (strpos($uri, '?') !== false) {
        $uri .= '&zfb=1';
    } else {
        $uri .= '?zfb=1';
    }
    $this->response->redirect($uri, true, 307);
}

Previously, in the bootstrap process, I set up my router with:

    $router->notFound(array(
        "controller" => "index",
        "action" => "fallBackToZend"
    ));

And now I have a mixed application, where the functionality yet rewritten is served by Phalcon, and the controllers/actions still to do are served by the old framework.