An introduction to the MVC Framework for Understanding MVC Programming in PHP _php tutorial

Source: Internet
Author: User
Tags smarty template ruby on rails
"What is MVC?" 】

MVC is a concept that allows you to reconcile the "three-part (that is, MVC's full name, Model, View, Controller)" to form a complex application. A car is a very good example of MVC in real life. We look at all two view (display) Parts: internal and external. And these two are inseparable from a controller (Controller): the driver. braking systems, steering wheels and other control systems represent models: they take control from the driver (Controller) and apply it to the interior and exterior (View).

"MVC on the Network"

The concepts covered by the MVC framework are fairly simple and extremely flexible. The basic concept is that you have a separate controller (such as index.php, which is now the mainstream development language) that controls all of the framework applications built on the basis of parameter requests. This controller usually contains (to a minimum) a parameter that defines the model, an event, and a get parameter. This allows the controller to confirm all requests and then run the corresponding events. For example, a/index.php like this (as the current mainstream development language)? Module=foo&event=bar's request is most likely to be used to load a class called Foo, and then run Foo::bar () [which is the bar () function ]。 The benefits of doing this are:

An interface that corresponds to all applications

It is cumbersome to maintain countless code within an application because each piece of code has its own relative path, database links, validation, and so on. Doing so will relieve you of your annoyance in this area, allowing you to merge and reuse the code

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

So far, I haven't seen much of the MVC framework written in PHP, which is now a mainstream development language. In fact, I only know a-solar that is completely written in PHP (as the current mainstream development language) 5. The other is cake, a ror (Ruby on rails-a ruby-language open-source network framework) that tries to become PHP (the mainstream development language of the present). I myself have some dissatisfaction with both frameworks: they do not take advantage of the existing code contained in Pear,smarty and so on, and now the cake is still more disordered; Finally, Solar is a work of the vast majority of one person (I don't mean to say that the author Paul is not a good person or programmer). These questions may not make you deny them, and it is likely that you do not care about them at all. But that is why I ask you to look at them as much as possible.

"The Old Way"

If you go back to 2001 to see your own code, the author may find a file called Template.txt, it looks like this: www.php (as the current mainstream development language) V.net reprint please indicate the source

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])) {

http://www.bkjia.com/PHPjc/508704.html www.bkjia.com true http://www.bkjia.com/PHPjc/508704.html techarticle "What is MVC?" "MVC is the concept of a complex application that allows you to reconcile the three-part (that is, MVC's full name, Model, View, Controller)." A car just ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.