Search code examples
phpzend-frameworkzend-dbzend-db-table

Model and Db-Table Zend Framework


I wanted to know is more correct to create a directly db-adapter or create a model that interfaces with db-adapter.

Make the classic operations crud with db-adapter, or you can create a model that passes then all of db-adapter:

scheme:

Controller -> Model -> Db-Adapter

or

Controller -> Db-Adapter

Application_Model_DbTable_Guestbook class extends Zend_Db_Table_Abstract
{
     / ** Table name * /
     protected $ _name = 'table';
}

Solution

  • A part of your model (for example a data mapper) uses the db adapter to store & retrieve stuff from the db. The controller only passes a request to the model. The model calculates stuff with the db adapter and passes it back to the controller. so that the controller can pass it to your view...

    So first:

    User Request -> Controller - > Big Model -> Small part of Model -> DB Adapter

    After that (but not every DB Request makes it to the user):

    DB Adapter responds -> Small part of Model -> Big Model -> Controller -> View -> User's screen = Response