Joakim Nygård Archive Linked About

Dynamic Extension of Zend_Db_Table and Friends

4 Sep 2009

I am currently working on a Zend Framework based webapp that requires an unusual amount of flexibility from in the database structure that backs it. The standard way of defining the database model mapping to data structures in Zend is to extend the Zend_Db_Table_Abstract in your model classes. Because of the flexibility required (and because modification of the codebase is to be kept at a minimum), this is not a viable route.

Zend_Db_Table_Abstract can automatically figure out the structure of the underlying table for each model using the database adapter’s DESCRIPE TABLE command, which usually makes it very easy to create basic models. Zend Framework 1.9.0 allows for concrete instances of Zend_Db_Table itself and using this detection capability, it is then possible to create the basics of a table model without creating the model class as a file. With Zend_Db_Table_Definition, also new in 1.9, it is possible to define a set of models with relations without creating any model classes.