I am in process of planning web application by following the best practices and approaches of software development. I am building this application using zend framework 2 and going through its documentation and best practices of building applications through zend framework 2 and MVC patterns.

Right now I am confused about where to keep my model layers. So far all the applications I have developed using Zend I used to keep my model layers in application module because I think models are not related to single module and a single module may communicate with multiple models. Also in Zf2 modules gets loaded only when it is requested except the Application module which loads with every request despite which module is requested. If I place my models in the specific modules and load them in the service config of there relative modules. I will not be able to use them in other modules.

So what should I do?

  • all modules are loaded for every request. If you couldn't use something, you might have tried using it before loading process complete. There's an event you can listen to to know when modules are ready. Also, more modules means more loading time.
    – imel96
    Commented Nov 17, 2013 at 23:10

1 Answer 1


You should not get worry about how the models will load. Zend Framework 2 is 'engineered' in modular way, what I want to say here is that it uses the famous design patterns (factory, dependency injection, service locater) and architecutral patterns to do the things. Remember, each module 'must be' cohesive in itself. And not coupled with any other module. Like the application module and your-other-module must implement their own models respectively to interact with the database. And in future if you replace your-other-module with some another-amazing-module, no other module would be disturbed.

At the end app runs, it integrates all the configurations in each module in one configuration and thus it works. Yes, it integrates all the end, but the framework is made to be modular and maintainable for long-lasting and separated chunks. You may use the chunks in your app or use whole MVC stack.

Thats why also a developer of Yii and CI, i feel Zend Framework 2 is most less forcing developers to use something and giving you so many choices. It may not be quick to develop apps in it but it is very flexible and a master piece.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.