I am working on small level of content management system (CMS) using Zend framework and Doctrine. To explain my question, I have created a simple structure, where I build two modules (Admin, Frontsite) as you can see in the following structure.
application
- configs
- controllers
- models
- modules
- frontsite
- controllers
-FrontController
-shownewsAction()
...
...
- models
- views
...
...
- admin
- controllers
-NewsController
- models
-news (extends newsbase)
-newsbase
- views
...
...
- views
Admin module handles all the admin requests, while frontsite module handles requests from visitors. If I create model (i.e news) in admin module and allow front controller from frontsite module to access it. Then my one module is going to be dependable to another module.
As far as I know, one purpose of modular approach is, to keep each module undependable, without relying on each other. One module can be taken off without having any effect on any module in the architecture. Well if that is one of the purpose of modular approach then I have to create same model (news) in front side models. This will cause the redundancy in my project, which is definitely not a part of object oriented design because it will hit its reusuablity purpose.
First approach, Do I need to create another common module where I will keep common models and allow other modules to get it accessed? Does this mean that my certain modules will only have VC architecture and will access models from common module?
Second approach, which I am thinking of is, creating some kind of service layer to help to communicate one module with another, would not that be dependable to each other again?
Another approach could be shifting all the common models to library folder. All modules will access them from library. In this way some of modules will become VC modules but won't rely on other modules. In this way we can promote reusability, eliminate redundancy, and keep the modules not dependable to each other.
What is the industry practice? Any expert opinion!
I have done some search in stackoverflow and google to get the answer. But none of them answered my question precisely.
Some searches are
I'm just doing exactly the same thing at the moment. I've setup my CMS with an 'Admin' module and a 'Frontend' module. I keep all my models in application/models
- not in either module.
Since the models don't specifically apply to only one module, it would seem best to put them 'above' modules in the structure.
I don't know what you have setup re autoloading, but for info, I have this in my Bootstrap:
protected function _initAutoload() {
$autoloader = Zend_Loader_Autoloader::getInstance();
ini_set('include_path', ini_get('include_path').";".APPLICATION_PATH);
$autoloader->registerNamespace('Models_');
...more code...
}