How to develop a MVC framework from scratch? [clos

2019-04-15 02:51发布

View is easy to be separated from MC,

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

I'm using PHP.

9条回答
祖国的老花朵
2楼-- · 2019-04-15 03:20

I would not start developing an MVC framework until the point when I knew what MVC was, very crisply and clearly, and was able to explain the difference between the model and the controller with my eyes closed. The way to do it is to learn from existing frameworks (Cake, Zend, QCubed, etc).

查看更多
等我变得足够好
3楼-- · 2019-04-15 03:24

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.

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.

查看更多
Emotional °昔
4楼-- · 2019-04-15 03:28

Maybe this is useful for you: http://www.phpmvc.net

查看更多
一纸荒年 Trace。
5楼-- · 2019-04-15 03:30

This could be a good starting point: MVC in PHP is a tutorial covering the basics of MVC.

查看更多
手持菜刀,她持情操
6楼-- · 2019-04-15 03:31

Start with the basics:

Understanding MVC Architecture from its Origin (part I) http://learnnewprogramming.com/blog/understanding-mvc-architecture/

查看更多
对你真心纯属浪费
7楼-- · 2019-04-15 03:33

Step 1: spend time contributing to an existing open source MVC framework.

Step 2: start contemplating making your own.

Step 3: stop panicking.

查看更多
登录 后发表回答