【问题标题】:In Zend/MVC how do I set up the controllers and views for a sub-application or submodule?在 Zend/MVC 中,如何为子应用程序或子模块设置控制器和视图?
【发布时间】:2011-06-30 03:23:40
【问题描述】:

我的所有 zend 应用程序都是这样的

/app/
/app/registration
/app/games

我需要为这样的游戏创建一个 URL

mydomain.com/games/game-1

当它像一个模块或子应用程序时,我如何在这个目录结构中设置控制器和视图?

/app/games
/app/games/configs
/app/games/controllers
/app/games/controllers/Game1Controller.php
/app/games/views
...

【问题讨论】:

    标签: php model-view-controller zend-framework controllers zend-framework-mvc


    【解决方案1】:

    一种方法是使用现有的模块约定:

    application/
      controllers/
      views/
      configs/
      modules/
        registration/
          controllers/
          views/
          configs/
    

    这样做的好处是 ZF 已经按照惯例在某种程度上处理了这个问题……如果你用另一种方式来做,你将不得不做更多的修改。

    在此布局中,顶级控制器、视图等是默认模块,而所有其他模块都在 modules 目录下。

    我也会让每个游戏都有自己的模块。如果你有在所有游戏中使用的通用代码制作类,你可以扩展这些类并将它们放在你的 library 中。

    【讨论】:

      【解决方案2】:

      您还可以使用 zf 工具zf.sh create module yourModuleName 为模块创建默认目录结构。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-04
        • 2013-11-30
        • 2014-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多