Home  >  Article  >  Backend Development  >  一个简单的PHP MVC演示_PHP教程

一个简单的PHP MVC演示_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:33:11755browse

为了更好的演示MVC的工作方式,我们使用了一个简单的新闻文章发布系统作为例子。分为使用MVC和不使用MVC两种方式。我们只作一个基本的演示,从数据库里读出一些文章列表,并在页面上显示。一般的流程就是,连接数据库,查询数据库,循环输出html结果。下面的代码就是如此做的。

   
   
       
        

News Articles

headline ?>

body ?>

采用MVC方式则如下。

model:


controller:


view:

   
   

News Articles

headline ?>

body ?>

将PHP代码直接写到HTML文件中,感觉不是很专业,也不安全。使用MVC会遇到其他一些问题,比如模板解析、路由转发等,不过这些都是后话了。这里只是简单演示下MVC的一个过程。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/752547.htmlTechArticle为了更好的演示MVC的工作方式,我们使用了一个简单的新闻文章发布系统作为例子。分为使用MVC和不使用MVC两种方式。我们只作一个基本的...
Statement:
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