模块与控制器

发布于 2024-10-20 01:01:56 字数 1369 浏览 2 评论 0原文

我正在为一个(哦,不,是另一个)PHP 框架编写一些零散的内容,作为一种学习经验,并希望将来能在较小的项目中使用。

我已经阅读了相当多的内容,即现有框架的参考文档。我经常看到模块这个词,根据我的阅读和以前的经验,模块是一个用于划分相关代码(视图、控制器、模型等)的概念

我好奇,SO 在这种情况下如何看待模块? (上下文是 MVC Web 应用程序架构或类似的应用程序开发模式)

我正在尝试确定如何最好地应用它,因为(我相信)它适合我当前的困境。对于音乐网站,模块将被视为 ArtistProducer 等,而控制器将是 ProfileMedia 等。这当然留下了操作,例如查看编辑

这一切看起来都很好,因为现在我可以像这样进行路由:

'Artist/Profile/View/{ALIAS}'
    +- Module : Artist
    +- Controller : Profile
    +- Action : View

//this may be accessed via music.com/artist/{alias}
//defaulting the Controller and Action

..但是我试图弄清楚模块概念如何适合这里,特别是我将如何组织或修改我的控制器以适应。


这就是我正在考虑的文件系统布局;

+- Root
    +- 'index.php'
    +- 'api.php'
    +- Modules
    |   +- Public
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- User
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- Artist
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- Producer
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- Venue
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- Administrator
    |       +- Controllers
    |       +- Views
    |
    +- Models
    +- Config
    +- ...

I'm writing the bits and pieces for a (oh no, another) PHP framework, as a learning experience, and hopefully for future use on smaller projects.

I've done a fair bit of reading, namely the Reference Docs of existing frameworks. I see the word Module thrown around alot, and from my reading and previous experience, a Module is a concept applied to divide related code (Views, Controllers, Models, etc.)

I'm curious, how does SO see a Module in this context? (context being MVC web application architecture, or similar application development pattern)

I'm trying to determine how best to apply this, as (I believe) it fits my current predicament. For a music website a module would be seen as an Artist, Producer, etc., whereas the Controllers would be Profile, Media, etc. This leaves actions of course, such as View, or Edit.

This all seems good, because now I can do routing like so:

'Artist/Profile/View/{ALIAS}'
    +- Module : Artist
    +- Controller : Profile
    +- Action : View

//this may be accessed via music.com/artist/{alias}
//defaulting the Controller and Action

..but I'm trying to figure out how the Module concept fits here, specifically, how I would organize or modify my Controllers to accommodate.


This is the sort of file system layout I'm thinking of;

+- Root
    +- 'index.php'
    +- 'api.php'
    +- Modules
    |   +- Public
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- User
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- Artist
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- Producer
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- Venue
    |   |   +- Controllers
    |   |   +- Views
    |   |
    |   +- Administrator
    |       +- Controllers
    |       +- Views
    |
    +- Models
    +- Config
    +- ...

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

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

发布评论

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

评论(2

雅心素梦 2024-10-27 01:01:56

模块(在 CakePHP 中称为插件)在大多数框架中几乎都是迷你应用程序。它们内部有自己的 MVC 结构,并且通常是自包含的,可能仅依赖于主要应用程序模型来保持代码可重用。

我们在工作中使用 Zend,模块的示例是

  1. 站点管理员对系统进行更改的管理模块。
  2. 用于网站一般前端的 Web 模块
  3. 用于拥有附加管理工具来在网站上执行活动的登录用户的用户模块

基本上所有这些模块都属于同一网站/系统,但处理方式大多不重叠。

Modules (called Plugins in CakePHP) are pretty much mini apps in most frameworks. They have their own MVC structure inside them and are usually self contained, maybe only relying on the main apps models to keep the code reusable.

We use Zend where we work, and examples of modules would be the

  1. Admin module for administrators of the site to do changes to the system.
  2. Web module for the general front end of the site
  3. User module for the logged in users who have additional management tools to carry out their activities on the site

Basically all of them fall under the same site/system, but deal in mostly non overlapping ways.

蓝戈者 2024-10-27 01:01:56

在最简单的情况下,模块将是应用程序中的一个文件夹(最好位于预先确定的位置,例如 /modules)。然后,每个模块内都会有一个完整的 MVC 堆栈,其中共享库和框架本身位于顶层。

In the simplest case, a module will be a folder in you app (preferably in a pre-determined location, like /modules). You will then have a whole MVC stack inside each module, with shared libraries and the framework itself being on the top level.

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