Reputation: 13334
I would like to start working with Zend Framework 2
and need some guidance as to the architecture of the framework. I compared Akrabat's ZF2 tutorial with it's ZF1 equivalent and the main difference I noticed so far seems to be the use of modules. I like the idea with modules as being independent and re-usable pieces of code and am thinking it could help segmenting my application and make it more maintainable. For instance I could have the following URL => module
mapping:
http://example.org/products => Products module
http://example.org/services => Services module
http://example.org/oauth => Oauth module
[...]
What I'm confused about, is that some of my modules will share the same underlying database resources (e.g. both Products
and Services
use the same table for comments) and therefore the same database models. Accordingly, I'm wondering:
Where should I put my database models when those are used by multiple modules?
Upvotes: 4
Views: 991
Reputation: 822
See the following article: http://adam.lundrigan.ca/2011/09/module-dependencies-in-zf2/
You can create a third module (example: Base, Main) that is a dependency for the Products and Services modules, or you can add the Models to one of your modules and use that module as a dependency for the other one.
Module.php
/**
* Get dependencies
*
* @return array
*/
public function getDependencies()
{
return array(
'BaseModule' => array(
'version' => '>=0.1.0',
'required' => true
),
);
}
Upvotes: 3