What are some of the ways you have implemented models in the Zend Framework?
I have seen the basic class User extends Zend_Db_Table_Abstract and then putting calls to that in your controllers:
$foo = new User;
$foo->fetchAll()
but what about more sophisticated uses? The Quickstart section of the documentation offers such an example but I still feel like I’m not getting a ‘best use’ example for models in Zend Framework. Any interesting implementations out there?
EDIT: I should clarify (in response to CMS’s comment)… I know about doing more complicated selects. I was interested in overall approaches to the Model concept and concrete examples of how others have implemented them (basically, the stuff the manual leaves out and the stuff that basic how-to’s gloss over)
I personally subclass both
Zend_Db_Table_AbstractandZend_Db_Table_Row_Abstract. The main difference between my code and yours is that explicitly treat the subclass ofZend_Db_Table_Abstractas a ‘table’ andZend_Db_Table_Row_Abstractas ‘row’. Very rarely do I see direct calls to select objects, SQL, or the built in ZF database methods in my controllers. I try to hide the logic of requesting specific records to calls for behindZend_Db_Table_Abstractlike so:There are numerous ways to approach this. Don’t think this is the only one, but I try to follow the intent of the ZF’s design. (Here are more of my thoughts and links on the subject.) This approach does get a little class heavy, but I feel it keeps the controllers focused on handling input and coordinating with the view; leaving the model to do the application specific work.