Where to put Service/Data Access Classes in a Zend Framework App
I originally wanted to fin开发者_JS百科d out how to access the Doctrine 2's Entity Manager from within Entity Classes. But I saw another question Using EntityManager inside Doctrine 2.0 entities, and learnt that I should be using a service class. I wonder where should I put in a Zend Framework Application? Also is it also called a DAO (Data Access Object)? I am thinking of naming it DAO instead of Service as Service sounds alot like something for external sites to use (like Web Service)?
I am thinking something like Application_Models_DAO_User
?
Service classes are part of the autoloader mapping. Like Application_Model_Something
can be found in application/models, it's the same for services.
An application service Application_Service_Something
should be located at: application/services/Something.php
When you use service classes inside modules, for example Blog_Service_Something
they need to be located at: application/modules/blog/services/Something.php
I think classes like entity managers shouldn't be part of your controllers nor your models, but located in service classes.
精彩评论