We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Migrating from CodeIgniter to Phalcon

Following on from a previous question by jasmad...

I am in the process of migrating an application from CodeIgniter to Phalcon, and I'm looking with eagle eyes (puh intended) at the models, which to me seem the easiest place to start (as well as having the biggest performance improvement for my project).

Are there any kind of tutorials/guides to migrating models from CodeIgniter to Phalcon knocking about? I've got a shedload of queries that look like:

$this->db->select("a.*")
         ->from("tableA a")
         ->some
         ->other
         ->conditions;

         $this->b_model->join($this->db, "a.idB")

and b_model might have a fn like this:

function join (&$db, $col) {
    $db->join("tableB b", $col . " = b.id", "left");
          ->select ("b.*");
}

Those are much simplified versions I've just typed up for conciseness, but hopefully it'll give an idea what I'm trying to achieve.

Just as a note, I don't want to use the in-built Phalcon relationship doodahs for reasons that are longwinded and will detract from the focus of the post. I just want to change those queries in to a PHQL query builder thing, also utilising some existing libraries & helpers that the CodeIgniter models use.

Anyway, yeah, is there some kind of guide for folk wanting to migrate? I don't mind writing up my experiences if there isn't, but it's always nice to have a guiding hand from someone who's done it before ... :)

Hi,

PHQL use in built Phalcon relationship, as it's the base of PHQL. So i don't think what you want can be done with PHQL.

We've "migrated" from CI to Phalcon, but rewriting eveything (but preserving the database). It's quite easy to do. You have to declare models and relations and with this you have already done 90% of the code.

Hi Olivier,

Thanks for replying. Yeah, I'd tried just adding in the relationships the normal Phalcon way, it was pretty easy and in most cases I would totally agree with you that it's the right way to do it.

However, in this case - because of the nature of the DB queries (one-to-many queries nested inside several other layers of one-to-many queries, so by the end a normal case would involve ~5k db queries for every request using the standard Phalcon method), the performance hit is so much that PHP just gives up/times out! An exceptional case would see many more queries. Anyway, the long and short of it is that I'd like the queries performned in a very specific way, since the performance can be very noticably improved by doing the right JOINs in the right places and parsing the data once it hits the PHP.

For the moment, I've just been rewriting the ActiveRecord queries to fit in with PHQL - you can do it, it's just not the most interesting work in the world!