model-view-controller - 在 "classical"web MVC 中, View 是如何创建的?

标签 model-view-controller view controller

在“经典”网络 MVC 中——如果我错了请纠正我:

  • Controller 将从“用户”(浏览器、控制台等)接收到的请求数据传递给模型层(由领域对象、映射器、存储库、服务等组成),
  • 模型层对其进行处理并返回一些结果数据
  • View - 作为专门的类 - 处理结果数据并将其发送/显示给“用户”。

我想问:

  • Controller 是否创建 View
  • 或者 Controller 是否将 View 作为依赖项接收
  • 或者 Controller 和 View 是否在前端 Controller 级别完全分开创建(比如说在 index.php 中)?

谢谢。

最佳答案

您对 MVC 的定义通常是正确的,这里是您问题的答案:

Controllers are not responsible for rendering the interface, nor for presentation logic. Controllers do not display anything. Instead, each controller's method deals with different user's request. It extracts the data from said request and passes it to model layer and the associated view.

Decisions about what and how to display are in purview of views. Views contain the presentation logic in MVC pattern. In the context of web applications, views create the response. They can compose a from from multiple templates or just send a single HTTP header.

Controllers can signal the associated view by passing some specific values of the request to that view, but most of the decisions in the view are based on information that the view requested from different services in the model layer.

A Controller's methods are based on what type of requests a user can send. For example in a authentication form it might be: GET /login and/or POST /login.

来源:Controllers , tereško


经典正确的MVC类结构:

Classic MVC class structure

简单定义:

Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

View. The view manages the display of information.

Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.

来源:Microsoft Docs

其他资源: (只有有用的)

外部

  1. MVC Explanatory [计算机科学设计模式]
  2. Creating a Custom Controller and View in CodeIgniter [视觉示例]
  3. Codeproject 的定义 MVC:easy | extended

内部

关于model-view-controller - 在 "classical"web MVC 中, View 是如何创建的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51149986/

相关文章:

ios - 从图像选择器返回时如何更改 View Controller ?

c# - 让 HttpClient 使用 app.config defaultProxy

swift - 按钮目标方法逻辑应该在 UIView 还是 UIViewController 中定义

java - MVC 模式的哪一层从数据库加载数据/将数据保存到数据库?

iphone - 使用 MVC 设计 iPhone 游戏的最佳实践?

Swift - 屏幕外的容器 View

php - Zend Framework 和防止胖 Controller

sql - 无法将 View 列的数据类型从数字更改为数字(4,1)

android - 整个屏幕的onTouchListener

symfony - Symfony2 Controller 中的构造函数