PS:这本书感觉不怎么样,这么多低频词就倒人胃口。。。

Suppose you'v recently launched a new web site, only to find that it's soon inundated(淹没) with users. Eager to extend this new found success, the project begins to grow in ambition and complexity. You'v even begun to hire a few talented staff members to help out with the design and development. The newly hired designers immediately begin an overhaul(检修) of the site's pages, many of which currently look like this:

<?php

// Include site configuration details and page header
INCLUDE "config.inc.php";
INCLUDE "header.inc.php"; // Scrub some data
$eid = htmlentities($_POST['eid']); // Retrieve desired employee's contact information
$query = "SELECT last_name, email, tel
FROM employees
WHERE employee_id = '$eid'";
$result = $mysqli->query($query, MYSQLI_STORE_RESULT); // Convert result row into variables
list($name, $email, $telephone) = $result->fetch_row();
?> <div id = "header">Contact Information for: <?php echo $name; ?>
Employ Name: <?php echo $name; ?> <br />
Email: <?php echo $email; ?> <br />
Telephone: <?php echo $telephone; ?> <br /> <div id="sectionheader">Recent Absences <?php
// Retrieve employee absences in order according to descending date
$query = "SELECT absence_date, reason
FROM absences WHERE employee_ids='$eid'
ORDER BY absence_date DESC ";
// Parse and execute the query
$result = $mysqli->query($query, MYSQLI_STORE_RESULT); // Output retrieved absence information
while (list($data, $reason) = $result->fetch_row()) echo "$date: $reason"; // Include page footer
INCLUDE "footer.inc.php";
?>

Becaus the design and logic are inextricably intertwined(纠缠在一起), several problems soon arise:

  • Because of the intermingling(混合、掺和) of the site's design and logic, the designers who were hired with the sole purpose of making your web site look great are now faced with the task of having to learn PHP.
  • The developers, who were hired to help out with the expansion of web site features, are distracted by fixing the bugs and security problems introduced by the disigner's novice(新手) PHP code. In the process, they decide to make their own little tweaks to the site design, infuriating(惹怒) the designers.
  • The almost constant conflicts that arise due to simultaneous editing of the same set of files soon become tiresome and time consuming.

You're probably noticing a pattern here: the lack of separation of concerns is breeding an environment of pain,  distrust, and inefficiency. But there is a solution that can go a long way toward alleviating(缓解) these issues: the MVC architecture.

The MVC approach renders development more efficient by breaking the application into three distinct components:the model, the view, and the controller. Doing so allows for each component to be created and maintained in isolation, thereby minimizing the residual(剩余) effects otherwise incurred should the components be intertwined in a manner similar to that illustrated in the previous example. You can find detailed definitions of each component in other learing resources, but for the purposes of this introduction the following will suffice(suffic-ient):

  • The model: The model specifies the rules for the domain modeled by your wesite, defining both the application's data and its behavior. For instance, suppose you create an application that serves as a conversion calculator,  allowing users to convert from pounds to kilograms, feet to miles, and Fahrenheit to Celsius, among other units. The model is responsible for defining the formulas used to perform such conversions, and when presented with a value and desired conversion scenario(无法理解,就当比率吧), the model carries out the conversion and returns the result. Note that the model is not responsible for formatting the data or presenting it to the user. This is handled by the view.
  • The view: The view is responsible for formatting the data returned by the model and presenting it to the user. it's possible for more than one view to utilize the same model, depending on how the conversion application: one targeting standard browsers, and one aptimized for mobile devices.
  • The Controller: The controller is responsible for determing how the application should respond based on events occurring within the model and the view to produce the appropriate response. A special controller known as a front controller is responsible for routing all requests to the appropriate controller and returning the response.

To help you better understand the dynamics of an MVC-driven framework, the following example works through a typical scenario involving the converter application, highlighting the role of each MVC component:

1. The user interacts with the view to specify which type of conversion he'd like to carry out, for instance converting an input temperature from Fahrenheit to Celsius.

2. The controller responds by identifying the appropriate conversion action,  gathering the input, and supplying it to the model.

3. The model converts the value from Fahrenheit to Celsius and returns the result to the controller.

4. The controller calls the appropriate view, passing along the calculated value. The view renders and returns the result to the user.

Introducing MVC的更多相关文章

  1. [转载]ASP.NET MVC 3的分部视图

    1.什么是分部视图,我们应该什么时候应该用? 作为一个对ASP.NET MVC 模型很熟悉的开发者,他们自然想创建一个内容和代码都可以重用的组件,在web 窗体,我们可以创建一个web用户控件或web ...

  2. 推荐一本不错的书《Sencha Ext JS 5 Bootcamp in a Book》

    原文:https://www.createspace.com/5425618 看了一下该书目录,感觉不错,Ext JS 5的重点内容都提及了,确实是一本学习Ext JS 5的好书,唯一遗憾的地方就是太 ...

  3. Introducing ASP.NET vNext and MVC 6

    [译]Introducing ASP.NET vNext and MVC 6 原文:http://www.infoq.com/news/2014/05/ASP.NET-vNext?utm_source ...

  4. [译]Introducing ASP.NET vNext and MVC 6

    原文:http://www.infoq.com/news/2014/05/ASP.NET-vNext?utm_source=tuicool Part of the ASP.NET vNext init ...

  5. [转]Code! MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)

    本文转自:https://www.asp.net/mvc/overview/security/create-an-aspnet-mvc-5-app-with-facebook-and-google-o ...

  6. ASP.NET MVC 6 一些不晓得的写法

    今天在看 Scott Guthrie 的一篇博文<Introducing ASP.NET 5>,在 MVC 6 中,发现有些之前不晓得的写法,这边简单记录下,算是对自己知识的补充,有些我并 ...

  7. ASP.NET MVC WebGrid – Performing true AJAX pagination and sorting 【转】

    ASP.NET MVC WebGrid – Performing true AJAX pagination and sorting FEBRUARY 27, 2012 14 COMMENTS WebG ...

  8. Pro ASP.NET MVC –第四章 语言特性精华

    C#语言有很多特性,并不是所有的程序员都了解本书我们将会使用的C#语言特性.因此,在本章,我们将了解一下作为一个好的MVC程序员需要了解C#语言的特性. 每个特性我们都只是简要介绍.如果你想深入了解L ...

  9. Introducing the Blog Module

    Introducing the Blog Module Now that we know about the basics of the zend-mvc skeleton application, ...

随机推荐

  1. 洛谷——P1630 求和

    P1630 求和 题目描述 求1^b+2^b+……+a^b的和除以10000的余数. 输入输出格式 输入格式: 第一行包含一个正整数N,表示共有N组测试数据: 接下来N行,每行包含两个正整数a和b. ...

  2. Flask实战第50天:cms添加轮播图的模态对话框制作

    编辑cms_banners.html, 在{% block main_content%}中加上表给内容如下 {% block main_content %} <table class=" ...

  3. 【Go】语法基础之结构体

    结构体的定义很简单: type Vertex struct { X, Y float64 } 可以理解为多个变量的集合. 结构体的使用: 1.直接使用: v := Vertex{1, 2} 或 var ...

  4. JZYZOJ1383 [usaco2003feb]impster 位运算 最短路

    http://172.20.6.3/Problem_Show.asp?id=1383  找能到达某个状态的最小操作数,然后把所有状态扫一遍即可,要额外判定一下起始就有的状态(如果起始里没有0那么这些状 ...

  5. [BZOJ 1855] 股票交易

    Link: BZOJ 1855 传送门 Solution: 比较明显的$dp$模型 令$dp[i][j]$为第$i$天持有$j$支股票时的最大利润 对其购买股票和售出股票分别$dp$,这里以购买为例: ...

  6. (原创)Stanford Machine Learning (by Andrew NG) --- (week 3) Logistic Regression & Regularization

    coursera上面Andrew NG的Machine learning课程地址为:https://www.coursera.org/course/ml 我曾经使用Logistic Regressio ...

  7. JVM 参数配置及详解 -Xms -Xmx -Xmn -Xss 调优总结

    堆大小设置 JVM 中最大堆大小有三方面限制: ①.相关操作系统的数据模型(32-bt还是64-bit)限制; ②.系统的可用虚拟内存限制; ③.系统的可用物理内存限制. 32位系统 下,一般限制在1 ...

  8. 活动中使用提示框(Toast)

    任务名称:活动中使用Toast 任务现象:点击button时,会弹出提示框:You Click Button 步骤 1.创建一个项目,新建活动和加载布局.参考: http://8c925c9a.wiz ...

  9. 从connect到express01-connect

    介绍 Connect是一个node中间件框架.每个中间件在http处理过程中通过改写request, response的数据.状态,实现了特定的功能. 根据中间件在整个http处理流程的位置,将中间件 ...

  10. 使用Hexo快速搭建一个博客,并部署到github

    本文旨在记录一下我在通过hexo搭建一个博客,并将其部署在github上面的过程,也供我自己在以后的使用过程中能够快速学习和参考.需要看更详细或者官方文档的可以点击Hexo官方文档进行查看. 安装前提 ...