Which PHP ORM works best with Zend Framework? - php

Well, seeing as I'm dissatisfied with Zend_Db_Table after being spoiled by LINQ, I'm looking to get started learning an ORM with PHP. General consensus seems to be that Doctrine and Propel are the only good ones for serious use -- and whatever my opinion, I'd like to use something at least moderately popular so that people in the future can look at this app I'm working on without having an head explosion :P
I'm currently leaning towards Propel because it's documentation seems to be a bit more complete, and it supports the nested set model (also called "modified preorder tree transversal model") right out of the box. However, I like Doctrine's use of namespaces and other PHP 5.3 features, and it seems to be a bit more popular.
From those who have used either ORM with Zend Framework, which meshes better with the existing framework (if either)? What kind of issues should I watch out for using either framework with Zend?

I can't speak for Propel but there are a lot of good integration resources for ZF and Doctrine. See Zend Framework 1.11 with Doctrine 2 Integration

Well Doctrine 1.2 supports Nested Set... much better than propel did in < 1.3. I havent used propel 1.4/5 so i cant comment on its current state. I also havent used Doctrine 2... ive been sticking with 1.2 since mot of my projects dont use php 5.3...
Overall I liked Propel better... I prefer generated classes to ones configured dynamically at runtime. Also keep i mind Propel is an active record implementation while Doctrine 2 uses the Data Mapper pattern.

Related

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

ORM in Django vs. PHP Doctrine

I am a PHP guy. In PHP I mainly use Doctrine ORM to deal with database issues. I am considering move to Python + Django recently. I know Python but don't have experience with Django. Can anyone who has good knowledge of both Doctrine and ORM in Django give me a comparison of features of these two ORM implementations?
I am a rare person who had to switch from Django 1.4 to Symfony 2.1 so I had to use Doctrine 2 instead of current Django ORM.
Maybe Doctrine can do many things but let me tell you that it is a nightmare for me to use it coming from Django.
I'm bored with the verbosity of php/Symfony/Doctrine ...
Also I never needed something that Django's ORM didn't manage already (maybe projects not big enough to reach the limits).
Simply compare the description of data between both orms (including setters & getters)...
The Django ORM does everything I want it to do. I've found it to be easier to use and more straight-forward than Doctrine. Sorry that I can't help with an in-depth comparison.
If you find the Django ORM is missing a feature you'd like to have, check out SQL Alchemy. It can easily be used with Django.
Ive used Doctrine over a 2 year project that ended 1.5 years ago, since then i've been doing mostly Django.
I prefer Djangos ORM over Doctrine any day, more features, more consistency, faster and shinier.
Django isn't just an orm. It is a web framework like symfony. The form framework in symfony is modeled on django for example. It's orm part is more like doctrine 2 I think, but I haven't played with either much.

Zend Framework: How to construct a simple "Data Mapper" model?

I'm building an application in the Zend Framework, but I'd like to implement a "Data Mapper" style ORM layer, constructing Model classes that only include the specific pieces of data they need to represent the domain concept (regardless of which tables those fields happen to belong to). Since my DB structure is highly normalized, the benefits gained from an Active Record ORM would be superficial.
So how would you implement a very simple, straightforward data mapper ORM layer in the Zend Framework?
I believe there's no true "Data Mapper" style ORM for PHP yet. If you want a true "Data Mapper", I think you might be out of luck.
There are 2 popular ORM in PHP, Propel and Doctrine. They are both more on the ActiveRecord side.
Doctrine in my own opinion is the go. At the moment, it's stable release 1.2 is not integrated with ZF yet. e.g. you cannot use the doctrine command line script to generate model classes for a modular ZF application setup.
However if you are running a single module ZF application, doctrine can be integrated pretty well. As #ArneRie pointed out, ZendCasts has got some really good videos. I learned a lot from it.
If you are interested, I also derived from it and made one of my own approach. You can find my blog post about this topic at http://blog.elinkmedia.net.au/2009/12/03/zf-doctrine-and-unit-tests/. You can download the source code of my sample app from github too.
Doctrine 2, which is currently in alpha (beta due 1 March 2010), is a data mapper orm inspired by JPA/Hibernate. Zend Framework has shelved their own Zend Entity component in favour of integrating Doctrine 2 with Zend Framework.
Depending on your timescales, you might want to look at Doctrine 2.
i would suggest to use Doctrine with the Zend Framework if you want to use an ORM. There are good Tutorials and Screencasts around with a lot of information.
Doctrine 1.2 with Zend Framework Screencast
The implementation details for creating an ORM can be quite extensive, and I lack the experience to give any meaningful recommendations beyond suggesting already existing projects, so I will suggest one instead.
The Data Mapper pattern is not very popular in the PHP world (in favour of Active Record, and certainly much of that favour is attributed to the fawning of Ruby on Rails in the PHP framework community), although there exists one notable project -- and it looks promising.
Outlet ORM follows the Data Mapper pattern, although I am not sure if it would be sufficient for your needs. I have so far had no problems with it.

PHP ORMs: Doctrine vs. Propel

I'm starting a new project with symfony which is readily integrated with Doctrine and Propel, but I of course need to make a choice.... I was wondering if more experienced people out there have general pros and/or cons for going with either of these two?
Thanks a lot.
EDIT:
Thanks for the all the responses, useful stuff. There's no truly correct answer to this question so I'll just mark as approved the one that got the most popular up-votes.
I'd go with Doctrine. It seems to me that it is a much more active project and being the default ORM for symfony it is better supported (even though officially the ORMs are considered equal).
Furthermore I better like the way you work with queries (DQL instead of Criteria):
<?php
// Propel
$c = new Criteria();
$c->add(ExamplePeer::ID, 20);
$items = ExamplePeer::doSelectJoinFoobar($c);
// Doctrine
$items = Doctrine_Query::create()
->from('Example e')
->leftJoin('e.Foobar')
->where('e.id = ?', 20)
->execute();
?>
(Doctrine's implementation is much more intuitive to me).
Also, I really prefer the way you manage relations in Doctrine.
I think this page from the Doctrine documentation is worth a read: http://www.doctrine-project.org/documentation/manual/1_2/en/introduction:doctrine-explained
To sum up: If I were starting a new project or had to choose between learning Doctrine and Propel I'd go for Doctrine any day.
I am biased, since I help a little bit on the next release of Propel, but you must consider that Propel was indeed the first ORM available, then lagged a bit when Doctrine got created, but now has active development again. Symfony 1.3/1.4 comes with Propel 1.4, where most comparisons stop at Propel 1.3. Also, the next release of Propel (1.5) will contain a lot of improvements, especially in the creation of you Criteria (resulting in less code for you to write).
I like Propel because it seems to be less complex than Doctrine: most code is in the few generated classes, whereas Doctrine has split up the functionality in lots of classes. I like to have a good understanding of the libraries I am using (not too much "magic"), but of course, I have more experience with Propel, so maybe Doctrine is not so complicated behind the scenes. Some say Propel is faster, but you should check this for yourself, and consider whether this outweighs other differences.
Maybe you should also consider the availability of Symfony plugins for the different frameworks. I believe Propel has an advantage here, but I don't know how many of the listed plugins are still up-to-date with the latest version of Symfony.
It comes down to personal preference.
I use Propel because (among other things) I like the fact that everything has its own concrete getter & setter method. In Doctrine, this is not the case.
Propel:
$person->setName('Derek');
echo $person->getName();
Doctrine:
$person->name = 'Derek';
echo $person->name;
The reason I like having getters & setters is that I can put all kinds of logic in them, if I need to. But that's just my personal preference.
I should also add that although Propel was slow-moving in the past, it is now under active development again. It has released several new versions in the past few months. The most recent version of Propel includes a "fluent query interface" similar to Doctrine's, so you don't have to use Criteria anymore if you don't want to.
It should be noted Doctrine 2 is currently in development released [ed] and functions almost completely different from the current stable version of Doctrine 1. It relies on the Data Mapper pattern instead of Active Record, and uses an 'entity manager' to handle persistence logic. When released it will bear closer resemblance to Java's Hibernate (Doctrine 1 is more like Rails' ActiveRecord).
I've been developing with the alpha release of Doctrine 2, and must say it is heads and shoulders above Doctrine 1 (just my opinion, and I've never used Propel). Chances are good that the Doctrine community will move toward it when it's released.
I would encourage you to check out Doctrine, but if you prefer the Active Record style that Propel and Doctrine use now, you might want to just stick with Propel.
The two references are somewhat outdated so you nevertheless cover some generalities, basically you'd have to evaluate your experience with the framework as such, a major drawback to doctrine is the inability to have an IDE that lets you auto-code in that propel is a winner, learning curves propel and doctrine are very different, it is easier to propel, if your project will need to manage complex data model uses doctrine, if you want to work quickly with an ORM which is best documented and find more support in Propel Internet uses, is much more mature and I believe that most used.
http://propel.posterous.com/propel-141-is-out
I'd suggest to use propel 1.6 which is better for IDE's autocomplete function.
I'm not a user of PHP 5 non-framework ORM, but here's some good comparison posts (in case you haven't seen them yet):
http://codeutopia.net/blog/2009/05/16/doctrine-vs-propel-2009-update/
http://trac.symfony-project.org/wiki/ComparingPropelAndDoctrine
Both conlusion favorite towards Doctrine as a newer generation of ORM for Symfony.
After using both of them for a number of years I prefer Propel 2 to Doctrine simply based on how you construct your query logic. Doctrine is as in depth as it can get and managing many aspects of it match that level of depth. Propel I feel has a more fluid and object driven way of building and managing the query interactions.
For me this led to less code in the model and more structures around how logic can/will be processed. This resulted in just building out many interactions as common functionality. (After all 90% of what you will do with a database is just going to be some degree of crud operation.)
In the end, both are powerful, manageable and will get the job done. My personal projects and interest use Propel ORM 2 and future projects, if still written in PHP will go that route.
I've been using both on a daily basis for the past 3-4 years.
I'd suggest using DbFinder Plugin. This is actually a very powerful plugin that supports both, and is quite a nice powerful. I actually like using it better than either.
If I'm not wrong, both ORMs use XML-based schema, and creating these schema definition is pretty cumbersome. If you need a PHP-based simple schema with fluent style. You may try LazyRecord https://github.com/c9s/LazyRecord it supports automatic migration and upgrade/downgrade script generators. And all the class files are generated statically without runtime cost.

Categories