自个儿动手设计 PHP MVC 框架(一)――URL
自己动手设计 PHP MVC 框架(一)――URL
?
在框架盛行的今天,MVC 也不再是神话。 经常听到很多程序员讨论哪个框架好,哪个框架不好, 其实?框架只是工具,没有好与不好,只有适合与不适合,适合自己的就是最好的。
每次我面试应届生时都会问他使用过什么框架,并谈谈对这些框架的理解。 当面试有经验的程序员时,会让他自己写一个框架出来。 其实也不是让他编码,只要有思路就 OK 了。 我觉得,如果一个有一年经验的程序员连一个 Framework v0.0.1 都开发不出来的话,肯定是没有深入理解一个框架。
前几天 @phoenixg 说要自己写个 MVC 框架。 而且他也确实不仅仅是说说而已,短短一个周末,这个框架雏形就神奇的出现在了?github?上。
这篇博文的名字是『自己动手设计?PHP MVC框架』, 所以本文不会涉及太多的编码,文中出现的任何代码片段都是我直接在 vim 里面敲的, 没做任何测试,如果想使用文中代码需自行测试。
跟随本教程,将从零开始设计一个属于自己的 MVC 框架。
我使用过 ZendFramwork、CodeIgniter,每个框架都有自己的优点和不足。 在写本文之前,我又看了 Symfony、cakephp、MooPHP、doitphp 等的核心源码, 下面说说我将把我的框架设计成什么样子,这一章主要讨论 URL 的设计。
1. REST
在这个 REST 横行的时代,如果一个框架不支持 REST,肯定被前卫程序员所瞧不起,所以本框架也要支持 REST。
第一个设计准则:?所有东西都是资源,资源有多种表现形式。
不管实际上存在的,还是抽象上的, 所有资源都会有一个不变的标识(ID),对资源的任何 API 操作都不应该改变资源的标识。
事实上,上面的这些完完全全是按照互联网的特性提出来的。
- 互联网中,一个 URL 就是一个资源;
- 资源的内容就是 HTML 页面;
- 不管怎么改 HTML 内容,URL 都不会改变;
- 资源之间通过 HTML 里的连接联系起来;
- 每次获取的时候,获取到的都是完整的 HTML 内容。
比如

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

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
