PHP 中的 HMVC 设计模式

发布于 2024-12-18 04:00:04 字数 163 浏览 5 评论 0原文

有数百个关于如何创建自己的简单 MVC 的教程,

我找不到任何如何用它实现 HMVC 的教程,但我确实了解 HMVC 是如何工作的,它有点像 Ajax,您可以从一个控制器请求多个控制器。

你能想出一些小的伪设计或 oop 设计 HMVC 是如何工作的?所以我会大致知道从哪里开始!

There are hundreds of tutorials of how to create your own simple MVC

I can't find any tutorial how to implement HMVC with it but I do understand how does HMVC work, it is a bit like Ajax, you can request many controllers from a controller.

Could you come up with small pseudo design or oop design how does HMVC work? So I will get rough idea where to start!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

习ぎ惯性依靠 2024-12-25 04:00:04

首先。 HMVC 有两种。

1 Kohana 风格。您可以在应用程序中访问其他控制器的位置

可能的实现:

  • 所有请求数据(URL、POST、GET ...)都存储在 Request 变量中。在这种情况下,所有控制器都无法直接访问 POST、GET 或其他请求变量。所有数据都应从 Request 变量中获取。

  • 当controller1执行访问controller2的方法时,新的(假的)Request实例被创建并传输到controller2。 Controller2不知道他不是通过真实请求执行的,而是通过假请求执行的,并像往常一样处理数据。

2 通过互联网进行真实的 HTTP 请求。在这种情况下,您可以访问控制器内的其他在线服务。不幸的是我不知道现实世界的例子。

可能的实现:使用 CURL

First of all. There are two kinds of HMVC.

1 Kohana style. Where you can access other controllers within you application

Possible implementation:

  • All request data (URL, POST, GET ...) are stored in Request variable. In this case none of controllers can access POST, GET or other request variables directly. All data should be taken from Request variable.

  • When controller1 executes method to access controller2, new (fake) Request instance is being created and transferred to controller2. Controller2 does not know that he is executed not via real request, but fake one and process data as usual.

2 Real HTTP request over the internet. In this case you can access other online services within your controller. Unfortunately I don't know real world examples.

Possible implementation: using CURL

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文