模块与控制器 [英] Module vs. Controller

查看:66
本文介绍了模块与控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为(哦,不,另一个)PHP框架写点点滴滴,作为学习的经验,希望将来可用于较小的项目.

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.

我已经读了很多书,即现有框架的参考文档.我看到很多单词 Module 乱七八糟,根据我的阅读和以前的经验,模块"是一个用于划分相关代码(视图,控制器,模型等)的概念.

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.)

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

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

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

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

..但是我试图弄清楚 Module 概念在这里的适用性,特别是我如何组织或修改控制器以适应.

..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
    +- ...

推荐答案

在大多数框架中,模块(在CakePHP中称为插件)几乎都是微型应用程序.它们内部具有自己的MVC结构,并且通常是独立的,也许仅依靠主应用程序模型来保持代码可重用.

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.

我们在工作的地方使用Zend,而模块的示例就是

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

  1. 管理员模块,用于站点管理员对系统进行更改.
  2. 网站一般前端的Web模块
  3. 已登录用户的用户模块,这些用户具有其他管理工具来执行站点上的活动

基本上所有它们都属于同一个站点/系统,但是大多数情况下都是不重叠的.

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

这篇关于模块与控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆