模块与控制器
我正在为一个(哦,不,是另一个)PHP 框架编写一些零散的内容,作为一种学习经验,并希望将来能在较小的项目中使用。
我已经阅读了相当多的内容,即现有框架的参考文档。我经常看到模块这个词,根据我的阅读和以前的经验,模块是一个用于划分相关代码(视图、控制器、模型等)的概念
我好奇,SO 在这种情况下如何看待模块? (上下文是 MVC Web 应用程序架构或类似的应用程序开发模式)
我正在尝试确定如何最好地应用它,因为(我相信)它适合我当前的困境。对于音乐网站,模块将被视为 Artist
、Producer
等,而控制器将是 Profile
、Media
等。这当然留下了操作,例如查看
或编辑
。
这一切看起来都很好,因为现在我可以像这样进行路由:
'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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
模块(在 CakePHP 中称为插件)在大多数框架中几乎都是迷你应用程序。它们内部有自己的 MVC 结构,并且通常是自包含的,可能仅依赖于主要应用程序模型来保持代码可重用。
我们在工作中使用 Zend,模块的示例是
基本上所有这些模块都属于同一网站/系统,但处理方式大多不重叠。
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
Basically all of them fall under the same site/system, but deal in mostly non overlapping ways.
在最简单的情况下,模块将是应用程序中的一个文件夹(最好位于预先确定的位置,例如
/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.