Home php教程 php手册 关于html、asp、php模板引擎、aspnet mvc、REST的一点思考

关于html、asp、php模板引擎、aspnet mvc、REST的一点思考

Jun 06, 2016 pm 07:36 PM
asp aspnet html m php about engine template

先看我对REST的 一点 认识,下面是《rest实战》 这本书的序言文字: 在我刚刚开始从事解决计算问题的时候,业界就有很多人有一个愿望:将系统设计为能够被自由组合的组件。互联网(Internet)无远弗届的广泛连接为这个愿望推波助澜,并且增加了一个新的愿望:

     先看我对REST的一点认识,下面是《rest实战》 这本书的序言文字:
      在我刚刚开始从事解决计算问题的时候,业界就有很多人有一个愿望:将系统设计为能够被自由组合的组件。互联网(Internet)无远弗届的广泛连接为这个愿望推波助澜,并且增加了一个新的愿望:使得组件在引入了延迟和不可靠性的网络之上也能正常工作。人们尝试了这个世界上的很多系统,其中的许多系统都失败了——通常伴随着悲伤的啜泣。
  一个伟大的成功案例是WWW(WorldWideWeb,万维网)。它的成功既渗透进了商业运转之中,也渗透进了流行文化之中。它为人们提供了一个机会:在全球范围内以几乎任意预先安排的协作方式从很多来源获取信息。
  正如我们现在所知道的,Web并非是计算问题的全部或者终极的解决方案,但是有很多人相信Web给我们上了重要的一课,即如何构造一个由网络化的组件组成的系统。很多人利用了Web的协议——HTTP来连接系统。但是有一些人认为我们应该更进一步,不仅仅将HTTP作为一种便于使用的数据通道,而是拥抱Web本身正常工作的方式,将其作为系统协作的基础。

这种思想集合在“REST”这个名字下,它所指的是RoyFielding的博士论文,这篇论文被提及的次数远远超过了它真正被阅读的次数。追随REST的原理成为了日益增长的共识,它为网络化的组件正常工作开辟了一条硕果累累的大路,而这条大路正建立在Web自身的巨大成功之上。
  这个愿景是很有吸引力的,但是为了达到目标还需要做很多事情。我们必须理解REST的原理,并且思考如何将其应用到系统集成每天所要解决的问题之上。这就是本书的作者所承担的任务:将REST从一个有吸引力的愿景变成一个已经实现的系统。他们已经做了很多,教会了我如何从资源的角度思考,如何使用HTTP的惯用语(idiom),以及超媒体控件(hypermediacontr01)的重要性。作为阅读的结果,本书将为你应用REST思想的核心元素打下坚实的基础。

REST”是一种思想,运用到开发上就是一种架构风格。
1)而使用“REST”的目的是什么了?
       通过上面这段文字可以得出就是用来开发大量的网络化组件,这样以后一个系统的设计就只要对这些网络化组件进行自由组合就可以了。
比如:现在大部分的互联网公司,阿里、百度、腾讯、优酷、新浪等都开发了自己的开发平台,对公布了很多业务接口提供给开发者进行二次开发,我们可以想象成这些接口就是我们系统中的组件,自己开发一个系统的时候直接用这些组件就可以了;当然现在这些网络组件还不是很多,不能完全满足支撑一个系统,但只要以后各个公司都遵循这种思想去做的话,系统的组件化是迟早的事。

2)互联网早就有了,那为什么REST现在才被提出来了?
       这我们就要回过头来看一下整个Web开发过程,从中寻找我们需要的答案。
互联网刚开始只是大家用来对文件、文字、图片等资源进行分享的,所以那时候的网页基本都是用HTML编写的静态页面,每一个url地址都是对应着一个唯一的资源,可能是一篇文章,也可以是一张图片。用现在的REST来看那时候的互联网是完全符合这种思想的。
让互联网紧紧做资源的分享,是不够的,我们还要在上面进行交互,业务处理等,那么动态脚本随之产生,代表就是现在还存在的asp 、php、aspnetmvc等。
       现在重点讨论asp、php模板引擎、aspnet mvc三者产生的原因,从而解答上面提出的问题。
asp是微软为了迎合市场推出的动态脚本语言,在自家的IIS服务器运行。原理也很简单,就是发送url请求后,IIS接收对地址中指定的asp文件进行编译,把里面的asp脚本代码转换为html代码再返回给浏览器。这样我们通过编写asp脚本就可以实现与前端的交互了,但是后来发现编写这种动态脚本是很痛苦的,调试麻烦,代码阅读性差,功能不好重用等。要解决这个问题就得把界面代码与动态脚本代码进行分离,那么就出现了模板引擎、MVC等程序结构。
个人觉得看php代码就是要先弄清楚代码中使用了什么样的模板引擎,把这个弄清楚后下面的代码就很顺畅了,不然总感觉云里雾里,找不到程序的脉络。
       觉得MVC应该是在模板引擎之后出现的,模板引擎只是解决了后台业务代码与前台界面代码直接的分离,而MVC对这些内容做了更明确的定义,把前台界面代码定义为View、后台业务代码定义为Model、再就是对界面的交互控制用Controller来处理。所以MVC成为了如今开发大一点的web系统的主流框架;
我们从语言谈到了程序结构,这跟我们想说明的REST又有什么关系了?
        很有关系,前面我说html时代其实是完全符合REST思想的,而到后面的asp、php、mvc就反而脱离了REST思想了。REST要达到组件化的目的,资源必须唯一标识,而动态语言,更确切的说是模板引擎、MVC完全打破了这种原则,因为他们是从业务功能的角度来设计程序的,这种设计使资源的访问动态化了,而这种动态的规则又只有程序设计者清楚,所以要想把这种功能组件化是不可能的;而现在Web系统原来越多,也离当初的设想原来越远所以重新提出REST这个概念,让我们不要在岔路上越走越远;

       总结:系统组件化在桌面时代一直没能够实现,而在互联网时代是完全有可能成功的,因为互联网的精神就是“开放、平等、协作、分享”。

本文章只是一个即兴所想,拿出来和大家分享一下,里面的观点不一定正确,请大家指正~~

 

       整过过程就是这样的,互联网刚开始的时候还是符合REST的,随着动态脚本的技术发展,设计的程序原来越偏离REST,所以现在重新提出REST,但不可能回到老路,那么就要把现在MVC技术改造为支持REST的一种新架构。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles