加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php – MVC:应该直接看模型吗?

发布时间:2020-05-25 09:57:32 所属栏目:PHP 来源:互联网
导读:早些时候,许多开发者认为视图不应该直接与模型通信,就像大多数框架一样. 然后,这个意见似乎是错误的,我找到一些文章,这些文章说这个观点可以直接与模型交流. http://r.je/views-are-not-templates.html http://www.tonymarston.net/php-mysql/model-view-cont

早些时候,许多开发者认为视图不应该直接与模型通信,就像大多数框架一样.

然后,这个意见似乎是错误的,我找到一些文章,这些文章说这个观点可以直接与模型交流.

http://r.je/views-are-not-templates.html
http://www.tonymarston.net/php-mysql/model-view-controller.html
Model,View,Controller confusion

How should a model be structured in MVC?

这些文章中的大多数引用了维基百科,模型视图控制器的一个块,引号是:

A view queries the model in order to generate an appropriate user interface (for example the view lists the shopping cart’s contents). The view gets its own data from the model. In some implementations,the controller may issue a general instruction to the view to render itself. In others,the view is automatically notified by the model of changes in state (Observer) that require a screen update.

啊,这是从维基百科,这样一个权威的网站,一定是对的!

但现在,当我打开MVC http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller的维基链接时,该页面将在今年9月14日(2013年)进行修改,上面的句子已经过去了.

视图的新定义是:

A view requests from the model through the controller the information that it needs to generate an output representation to the user.

现在我再次感到困惑,新的定义表示视图应该通过控制器从模型中请求数据…

视图访问模式是否直接在地球上?

以下是经典MVC架构中依赖关系的表示.你会注意到没有箭头指向控制器来查看,因为它是新增的:

资料来源:GUI architectures

然后,依赖关系映射更接近于“MVC框架”中通常会看到的内容:

资料来源:Passive view

“被动视图”配置不是MVC架构的一部分.虽然它使用相同的名称,但它实际上是MVP模式的变体(您可以在this publication中找到更长更详细的描述)

底线:是的,如果您正在实现MVC或类似MVC的架构,那么您的视图应该是从模型层请求信息.

此外,您应该注意,这不是所谓的“mvc框架”正在推动的.在类似Rails的框架中,没有任何意见.相反(由于原始结构是为原型结构而制作的)视图被愚蠢的模板所取代,并且视图的所有职责都被推送到他们称为“控制器”的东西中.

基本上,IMHO,名为Rails的模式的最佳方式是OLT:ORM-Logic-Template.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读