How to use Zend_Db without SQL Queries?
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 Gatewa开发者_开发问答y pattern and ModelMapper class but I can't figure it out.
Can someone shine my path? :P
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:
- Good PHP ORM Library?
精彩评论