Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 771
wormhit Avatar asked May 17 '13 08:05

wormhit


1 Answers

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.
like image 106
wormhit Avatar answered Sep 27 '22 19:09

wormhit