Here is a little context:
I am writing a project in PHP using the Zend Framework, and I have some E / R diagrams from past client meetings. The database schema was written for MySQL, and now it's time to implement my models in Zend. I am new to Zend, so I donβt know how to start writing this code.
The first thing I noticed when reading their documentation was that the quick guide used the data gateway template, but this did not happen on its Zend_DB links page.
// Data Gateway Sample // <application/models/UserMapper.php> class Application_Model_UserMapper() { // ... Methods to read/write from DB } // <application/models/DbTable/Users.php> class Application_Model_DbTable_Users { // Relationship infromation etc. } // <application/models/User.php> class Application_Model_User { // At last, model specific data // using UserMapper->find($id, $model); }
After looking at stackoverflow for some time, hoping to find pointers on how to organize models most efficiently, I came across another recommended solution.
Now the solution above looks very clean, but I still have one question before I set out to write my code:
Should I use Row_Abstract subclasses to store the data model, or should I create separate models that have no other purpose than storing data?
The latter looks like a lot of duplicate efforts (Model_DbTable, Model, Mapper, [Row?])
// What I have in mind // <application/models/DbTable/Users.php> class Application_Model_DbTable_Users { // Relationship infromation etc. } // <application/models/User.php class Application_Model_User extends Zend_Db_Table_Row_Abstract { // Model stuff here // Relationship fetch helpers here // ...? } // Perhaps a Rowset_Abstract class if it is ever needed?
alxbl source share