views:

157

answers:

1

The last time I worked with Zend_Db I recall I used to write SQL Queries manually. I've been searching for some ORM application, but, since I read something like Zend_Db is also capable of doing so, I started to try it, but I can't find neither a good tutorial explain it or a good documentation.

I read something lake Gateway pattern and ModelMapper class but I can't figure it out.

Can someone shine my path? :P

+2  A: 

Everything you need to get started is available in the Zend Framework Reference Guide on Zend_Db.

Zend_Db_Table is a TableData Gateway. It has very limited ORM capabilities. Mainly these stem from the ability to define relationships between tables. Dependent rowsets can be lazy loaded with appropriate finder methods on the Zend_Db_Row instances returned by a query to a TDG. Doing so will not necessarily make you write no SQL, but less SQL. Under the hood, Zend_Db_Table uses a subclass of Zend_Db_Select to build the SQL queries through a Fluent API. See the reference guide on how to work with TDGs and how to fetch related data.

The ModelMapper you are refering to is another pattern, called DataMapper. This is usually utilized when working with a Domain Model. A DataMapper handles the impedance mismatch that usually occurs when Domain objects and their persistent representation do not match. There is no standard recipe for this class. Depending on the amount of mismatch, DataMapper can become rather complex. Efforts to create a generic mapper for ZF were discontinued in favor of integrating Doctrine with ZF. But an example of a custom DataMapper can be found in the reference guide.

You might want to look around SO for PHP ORM's, particularly this question:

Gordon
+1 There are some nice articles available online that explain how you could integrate Propel or Doctrine in your Zend apps ie. http://ruben.savanne.be/articles/integrating-zend-framework-and-doctrine, http://devzone.zend.com/article/184
wimvds
wow! I didn't expected all that stuff.. thx!!
Rodrigo Alves