Where to put DQL's?
Reference To This Q开发者_开发知识库uestion
Where one should put the DQL queries? In a service class, or in a controller or maybe in a repository class?
Found a nice article about this, which answers my question. I think it's best to put them in the service class.
How to integrate Doctrine 2 with your Zend Framework application
This highly depends on what your DQLs are doing:
If you have a Query which is doing work on only one entity type I suggest to create your own Repository class for this entity. The repository class already provides you with the methods for find and findAll, so it would fit there good.
Doctrine gives you orm:generate-repositories
as CLI tool. Ralph Schindler took this approach as you can see in his example repository.
If you have a Query which affects multiply types of entities, the Service Layer should be the best place to put it.
精彩评论