网络应用程序开发的MVC与HMVC[英] MVC vs HMVC for web application development



我正在使用MVC模式进行Web开发.我使用Codeigniter框架.我找到了 and 和,他们正在使用HMVC.仍然不明确HMVC,为什么我们应该使用HMVC代替MVC?阅读HMVC模式后,我感到困惑,这与MVC并没有太大不同.您能解释一下为什么我们应该将HMVC用于Web应用程序开发?


层次模型 - 视图控制器(HMVC)模式是直接的 扩展到设法解决许多的MVC模式 已提到的可伸缩性问题. HMVC首先在 博客文章的标题为 客户层 2000年7月在Javaworld网站上. 文章集中于与图形用户一起使用HMVC的好处 接口.已经有一些建议作者 实际重新解释了另一种称为的模式 1987年描述的演示文稿-Abstraction-Control(PAC). 在Javaworld中,提供了有关HMVC如何帮助进来的详细说明 使用GUIS的桌面应用程序的设计.重点 文章是为了证明如何使用HMVC来创建可扩展的Web 申请.

HMVC是传统的MVC三合会的集合 应用.每个三合会都是完全独立的,可以执行 没有其他任何.对三合会提出的所有请求必须 使用控制器接口,永不加载模型或库 在自己的领域之外.三合会内的物理位置 托管环境并不重要,只要可以从 系统的所有其他部分. HMVC的独特功能 鼓励现有代码的重复使用,简化了不同的测试 系统的一部分并确保应用程序很容易 增强或扩展.

来自用HMVC缩放Web应用程序 由Sam de Freyssinet





  • 在其他项目中重复使用您的代码
  • 简化维护您的项目
  • 扩展您的项目
  • 组织代码
  • 模块化结构

尝试HMVC后,您永远不会回到MVC 这是一张更清晰的图片



模块化扩展使Codeigniter PHP框架模块化.模块是独立组件的组, 通常在应用程序模块子目录中安排的模型,控制器和视图,可以将其放入其他Codeigniter应用程序中.





list = plbepr3pmwcawdz6fgnyoyvicez4hrjpec时间plbepr3pmwcawdz6fgnyoyvicez4hrjpec&index = 1




I'm using MVC pattern for web development. I use codeIgniter framework. I found and , they are using HMVC. It still not is clear of HMVC and why we should use HMVC instead of MVC ? I am confused after reading HMVC pattern and it's not too much different from MVC. Can you explain why we should use HMVC for web application development ?


The Hierarchical-Model-View-Controller (HMVC) pattern is a direct extension to the MVC pattern that manages to solve many of the scalability issues already mentioned. HMVC was first described in a blog post entitled HMVC: The layered pattern for developing strong client tiers on the JavaWorld web site in July 2000. Much of the article concentrates on the benefits of using HMVC with graphical user interfaces. There has been some suggestion that the authors where actually re-interpreting another pattern called Presentation-Abstraction-Control (PAC) described in 1987. The article in JavaWorld provides a detailed explanation of how HMVC can aid in the design of desktop applications with GUIs. The focus of this article is to demonstrate how HMVC can be used to create scalable web applications.

HMVC is a collection of traditional MVC triads operating as one application. Each triad is completely independent and can execute without the presence of any other. All requests made to triads must use the controller interface, never loading models or libraries outside of their own domain. The triads physical location within the hosting environment is not important, as long as it is accessible from all other parts of the system. The distinct features of HMVC encourages the reuse of existing code, simplifies testing of disparate parts of the system and ensures that the application is easily enhanced or extended.

From Scaling Web Applications with HMVC by Sam de Freyssinet


HMVC can do anything that MVC can and more

one of the things that you will or had struggled with in MVC is that you can't call a controller from another controller (unless you use a custom library or helper to do that)

in HMVC (Hierarchical Model View Controller) you can do that , i would sum all the qualities in here:

  • reuse your code in other projects
  • simplify maintaining your project
  • scale your project
  • organize code
  • modular structure

you will never go back to MVC after trying HMVC here is a picture to be more clear

See picture

for CodeIgniter use "Modular Extensions - HMVC"

Modular Extensions makes the CodeIgniter PHP framework modular. Modules are groups of independent components, typically model, controller and view, arranged in an application modules sub-directory that can be dropped into other CodeIgniter applications.

Module Controllers can be used as normal Controllers or HMVC Controllers and they can be used as widgets to help you build view partials.

if you want to use codeigniter with HMVC pattern, you can use Modular Extensions - HMVC here

and here are some nice and funny video tutorials that will get you on rails with HMCV in codeigniter

hope that helps!