php - Zend Framework 2 模块和模型架构所需的建议

标签 php model-view-controller zend-framework architecture

我想开始使用 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
[...]

让我感到困惑的是,我的一些模块将共享相同的底层数据库资源(例如,ProductsServices 使用相同的表进行注释)因此具有相同的数据库模型。因此,我想知道:

当多个模块使用数据库模型时,我应该把它们放在哪里?

最佳答案

请参阅以下文章: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/

相关文章:

php - 在zend框架中使用jquery发布数据

php - 文本框自动填充 mysql 数据,但不填充文本区域

php - 使用远程数据库、ubuntu、apache2 的本地 wordpress

php - MYSQL/PHP 选择

ios - 了解uiview和uiviewcontroller

c# - GRASP的Controllers和MVC的Controllers问题

zend-framework - 尝试截断Zend Db单元测试失败

zend-framework - Zend 框架组由

php - Nginx - 无法打开流 : Permission denied in/var/www/example. com

grails - 在 View 定义中生成的实例