Home  >  Article  >  Backend Development  >  Understanding MVC Programming in PHP - Introduction to the MVC Framework_PHP Tutorial

Understanding MVC Programming in PHP - Introduction to the MVC Framework_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:32:32750browse

 【What is MVC? 】

MVC is a concept that allows you to harmoniously combine "three parts (namely, the full name of MVC, Model, View, and Controller)" to form a complex application. A car is a very good example of MVC in real life. When we look at a car, we look at two View (display) parts: interior and exterior. Both of these are inseparable from a Controller: the driver. The brake system, steering wheel, and other control systems represent the Model: they take the control methods from the driver (Controller) and apply them to the interior and exterior (View).

 【MVC on the Web】

 The concepts covered by the MVC framework are quite simple and extremely flexible. The basic concept is that you have a single controller (such as index.php(as the current mainstream development language)) that controls all in-frame applications based on parameter requests. This controller usually contains (minimally) a parameter that defines the model, an event, and a GET parameter. This way the controller can acknowledge all requests and run the appropriate events. For example, a request like this /index.php(as the current mainstream development language)?module=foo&event=bar is likely to be used to load a class named foo , and then run foo::bar() [which is the bar() function]. The advantages of this are:

An interface corresponding to all applications

It is very troublesome to maintain countless codes in an application at the same time, because each piece of code has its own relative path and database link , verification, etc. Doing so will save you the trouble in this regard and allow you to merge and reuse code

 【Why create the author's own MVC framework? 】

So far, I have not seen too many MVC frameworks written in php(as the current mainstream development language). In fact, I only know one - Solar, which is completely written in php(as the current mainstream development language)5. The other one is Cake, a RoR (Ruby on Rails-a Ruby language open source network framework) that tries to become php(as the current mainstream development language). I myself have some dissatisfaction with both frameworks: they do not take advantage of the existing code included in PEAR, Smarty, etc.; the current Cake is still relatively messy; finally, Solar is a framework written mostly by one person. (I don't mean to say that its author, Paul, is not a good person or a good programmer). These questions probably don't make you deny them, and chances are you don't care about them at all. But because of this, I ask you to look at them as much as possible.

【Old Way】

If you go back to 2001 and look at the code you wrote, the author may find a file called template.txt, which looks like this: www.php (As the current mainstream development language) v.net Please indicate the source for reprinting

<?php (As the current mainstream development language)
require_once(config .php(as the current mainstream development language)); // Other requires, DB info, etc.

$APP_DB = mydb;
$APP_REQUIRE_LOGIN = false; // Set to true if script requires login
 $APP_TEMPLATE_FILE = foo.php(as the current mainstream development language); // Smarty template
$APP_TITLE = My Application;

if ($APP_REQUIRE_LOGIN == true) {
if (!isset($_SESSION[userID])) {

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508704.htmlTechArticle【What is MVC? ] MVC is a concept that allows you to harmoniously combine "three parts (namely, the full name of MVC, Model, View, and Controller)" to form a complex application. A car is...
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