我想开始使用 Zend Framework 2
并需要一些关于框架架构的指导。我比较了Akrabat's ZF2 tutorial有了它 ZF1 equivalent到目前为止我注意到的主要区别似乎是使用 modules .我喜欢模块作为独立且可重复使用的代码片段的想法,我认为它可以帮助分割我的应用程序并使其更易于维护。例如,我可以有以下 URL => module
映射:
http://example.org/products => Products module
http://example.org/services => Services module
http://example.org/oauth => Oauth module
[...]
让我感到困惑的是,我的一些模块将共享相同的底层数据库资源(例如,Products
和 Services
使用相同的表进行注释)因此具有相同的数据库模型。因此,我想知道:
当多个模块使用数据库模型时,我应该把它们放在哪里?
最佳答案
请参阅以下文章:http://adam.lundrigan.ca/2011/09/module-dependencies-in-zf2/
您可以创建第三个模块(例如:Base、Main)作为产品和服务模块的依赖项,或者您可以将模型添加到您的一个模块并将该模块用作另一个模块的依赖项。
模块.php
/**
* Get dependencies
*
* @return array
*/
public function getDependencies()
{
return array(
'BaseModule' => array(
'version' => '>=0.1.0',
'required' => true
),
);
}
关于php - Zend Framework 2 模块和模型架构所需的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10796180/