如何从头开始开发MVC框架? [英] How to develop a MVC framework from scratch?

查看:90
本文介绍了如何从头开始开发MVC框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

视图很容易与MC分开,

View is easy to be separated from MC,

但是如何分隔M和C?对我来说,这种区别似乎有点含糊不清.

but how to separate M and C?The difference seems a little vague to me.

我正在使用PHP.

推荐答案

MVC的模型"部分是指数据访问层,因此您应该创建类以读取/写入数据库.通常,它是每个数据库实体"的一个模型,因此,例如,一个文章类,一个类别类以及一个简单的数据库类就是一个好主意.

The "model" part of MVC refers to the data access layer, so you should create classes to read from/write to the database. Often it's one model per database "entity", so, say, one class for articles, one class for categories, plus a simple database class is a good idea.

控制器"部分是通用逻辑,通常是入口点.在这里,您检查了输入页面和请求页面,使用该模型查找正确的数据并将其存储在该视图的变量中.

The "controller" part is the general logic, and usually the entry point. Here you check the input and requested page, use the model to find the correct data and store in variables for the view.

您所说的视图"部分非常简单.只需从控制器中添加一个文件,该文件主要由HTML组成,但是会输出PHP变量.

The "view" part as you said is quite easy. Just include a file from the controller that mostly consists of HTML but outputs your PHP variables.

这篇关于如何从头开始开发MVC框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆