Migrating from CodeIgniter to Phalcon - php

Note before we start: I've asked this question on the Phalcon forum as well as here to try and broadcast the question a bit wider.
Following on from a question on the Phalcon discussion board by jasmad...
I am in the process of migrating an application from CodeIgniter to Phalcon, and I'm looking with eagle eyes (pun 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? Has anybody got experience in doing this that they'd mind sharing?
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 ... :)

model manager is one of service in phalcon, so you can add your model manager to dependency injector taken from cakephp and have all your old queries working fine. Of course, if you want to use phalcon's models, i wonder if you would be good to go without changing your code.

Related

Laravel 3 : Looking for explanation how to use the model

I'm new at MVC and my first framework is Laravel (3 for now). I've started coding exclusively in the routes, and I moved to the controller. I'm however doing all of my database operations in the controller. I do not understand how to use the model.
Examples either demonstrate everything in the controller or in the route, but they never split the model, controller and view.
Could anyone kindly explain me how to use the model? In short I don't understand how to link one to each other, like sending form input to them model, or processed data back to the controller.
A github repo of a Laravel (v3 if possible) with a full MVC setup would be nice to analyze too, if anyone has one up for me to look at?
Thanks.
The best statement on the subject of Frameworks I've heard is due to Uncle Bob:
A good Architecture allows major decisions to be deferred!
Specifically:
A good Architecture delays choosing a Framework!
Another great piece to think about:
MVC is not an Architecture! It is a Delivery Design Pattern.
Watch his video - it is one of the sadly few ones out there that don't spend 1000 words on what can be said in 10 and I can't highly enough recommend it - and it will help you to understand many points raised in your question:
Robert C Martin(Uncle Bob) -Clean Architecture and Design - Video
Of course, his book on Clean Code is also highly recommended!
Although this link is for Laravel 4 docs, it may help you understand how the models work - (Laravel 3 also uses Eloquent):
http://laravel.com/docs/eloquent
Also, specific to laravel 3:
http://codehappy.daylerees.com/eloquent-orm

PHP Datamapper And ORM

I am starting with PHP DATAMAPPER AND ORM.. I am completely new with it. Though I got knowledge about through google. It really found interesting.
I have few doubts with it.
Can I use Doctrine 2 library/ORM with my Core PHP Project. Or it is only for framework like CodeIgnitor, Zend or else.
Is it really helpful for fast development. Or it may get expanded after some extent.
Can I have any example/ esp. tutorial where I can implement it with CORE PROJECT means some blog or else.
I checked with phpdatamapper.com. I found it easy but it was quite old as not updated since last 3 years. Is it good to implement that ? Any source implement that.
I would really be pleased having source/implementation (simply on blog) on github or else somewhere. Please
ORM like doctrine can be used with every project, it does not need any framework. You can include them in your projects with composer.
About Doctrine, you can use two things depending on what you want to do :
Doctrine\ORM and its whole bundle. It brings you the whole functionality, with its ORM and other cool stufs. If you want to use it, you have to put that line on your composer.json file :
{"require":
{"doctrine/orm": "2.3.2"}
}
Doctrine\DBAL. It is only a abstraction layer without the ORM functionality. It is here to bring you more functionalities to PDO, and build queries without taking care of your data base engine. As it has no ORM it is faster to execute but it does not bring any conception facility.
If I introduce you to these two tools it is because you will have a choice to make. If you want a simple blog site, Doctrine\DBAL is what you want as it will bring no performance issue.
If you want a bigger application with a full architecture, you need Doctrine\ORM as it will help you to build and keep your data base safe.
About tutorials, the documentation is built like one so I think you can get started here for the ORM and here for Doctrine\DBAL

PHP ORM frameworks with features similar to ADO.NET Entity Framework Code First?

I'm coming from .NET world back to PHP for some side projects. I am comfortable with PHP as a language, but am kind of lost in many PHP frameworks available today. Back in the days I did PHP we just wrote SQL queries, so I have no idea what is possible with PHP today in terms of ORM, therefore the question.
I got used to creating my database models using ADO.NET Entity Framework Code First and I like this approach, so I am looking for a PHP ORM framework with similar set of features.
If I understand you correctly, you are searching a framework with something like AR and CRUD.
I think almost every more famous PHP framework have this options.
Anyway, I am using Yii framework and I can say it's one of the best options, but you can surf a little to see which framework can fit your requirements.
You can create DB with table relations etc, and the generator will create your models + relations for the Active Record. Also CRUD generator can create and the View/Controller part.
You should review current PHP ORM frameworks, you may find something that they offer that the ADO.Net framework does not.
What is the easiest to use ORM framework for PHP?
This stack question is very detailed around your question: Good PHP ORM Library?.
Everyone has an opinion, some better than others.
have a look at Doctrine or Propel ORM

PHP Commercial Project Function define

Currently I am working with a commercial project with PHP. I think this question not really apply to PHP for all programming language, just want to discuss how your guys solve it.
I work in MVC framework (CodeIgniter).
all the database transaction code in model class.
Previously, I seperate different search criteria with different function name.
Just an example
function get_student_detail_by_ID($id){}
function get_student_detail_by_name($name){}
as you can see the function actually can merge to one, just add a parameter for it. But something you are rushing with project, you won't look back previously got what similar function just make some changes can meet the goal. In this case, we found that there is a lot function there and hard to maintenance.
Recently, we try to group the entity to one ultimate search
something like this
function get_ResList($is_row_count=FALSE, $record_start=0, $arr_search_criteria='', $paging_limit=20, $orderby='name', $sortdir='ASC')
we try to make this function to fit all the searching criteria. However, our system getting bigger and bigger, the search criteria not more 1-2 tables. It require join with other table with different purpose.
What we had done is using IF ELSE,
if(bla bla bla)
{
$sql_join = JOIN_SOME_TABLE;
$sql_where = CONDITION;
}
at the end, we found that very hard to maintance the function. it is very hard to debug as well.
I would like to ask your opinion, what is the commercial solution they solve this kind of issue, how to define a function and how to revise it. I think this is link project management skill. Hope you willing to share with us.
Thanks.
If you're using codeigniter, just use:
http://www.overzealous.com/dmz/
I don't know what I even used to do without it.
Congratulations, you have invented an ORM :)
There are plenty of commercial ORM solutions but, in my opinion, all they no better than yours. And I'd go for good ol' SQL.
After I did some research on ORM vs Active Record. For my situation I didn't find a lot of help by switching to ORM will help me better.
I found out that ORM is not do very in READ data. But good in Create, Update, and Delete.
My current solution is every model recompile the my own OR_WHERE() / AND_WHERE(), before pass to the $this->db->query(). It is more easy to maintain and customize.

CRUD Class for PHP (Simple but will Allow Relational Data)

I am building a database of products and manufacturers. I already have the database layout done. I am looking for a simple CRUD class that will let me setup Manufacturers and Products and create the records quickly and easily. I have looked at ORM's but they all seem to be over kill for what I am looking for. Thanks
Take a look at Grocery CRUD, it is easy to use, has nice views with call backs. Might fit your needs. Check it out at http://www.web-and-development.com/grocery_crud/
Look into CakePHP. The code generation (or scaffolding) will get you a working CRUD interface in a few minutes.
I know this question is fairly old, but I came across this jQGrid + PHP component, and for straight out install-and-go simplicity, it's hard to beat.
Hard to say with so few informations...
CouchDB + PHPillow if you don't neccessarily need SQL - works quite nice,
Zend_DB + (Sqlite|MySql|Postgress) otherwise ...
Try Symfony. It's got good performance. Both Symfony and Doctrine (ORM used) have really good documentation sites.
http://www.symfony-project.org/

Categories