Search code examples
databasezend-framework2zend-db

zf2 - Zend\Db - What do Model, Entity, Hydrator, Mapper, TableGateway do and how it all links together?


Please explain what

  • Model
  • Entity
  • TableGateway
  • Mapper
  • Hydrator

do and how it all works together in zf2 application.

please don't give links to blogs articles. I need simple big picture explenation.


As far as I understand these are the same:?

Model    == Entity
Hydrator == Mapper

Solution

  • If we take for example one db table. Then:

    • Model will represent one row class where class variables would be columns.
    • Entity is the same concept as Model used by Doctrine.
    • TableGateway is parth from Table Gateway pattern. It will have information about table name. This is place where all query methods will be located. Used in all zf2 examples.
    • Mapper is parth from Data Mapper pattern. It is more advanced way of handling the same problem what TableGateway is doing.
    • Hydrator is changing your select query row results from array to Model object. If not provided then zf2 will use ArrayObject instead.