An introduction to the MVC Framework for Understanding MVC programming in PHP

Source: Internet
Author: User
Tags ldap
"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) that controls all the applications built into the framework based on the parameter request. 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?module=foo&event=bar request like this would probably 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 too many MVC frameworks written in PHP. In fact, I only know a-solar, which is completely written in PHP5. The other one is cake, an attempt to become a PHP ror (rubyalign=centerbgcolor= #e3e3e3border =1>

  setfetchmode (DB_FETCHMODE_ASSOC);  }else{die ($db->getmessage ()); }//putyourlogichere//outputthetemplate include_once (app_template_path. '  /header.php '); Include_once (App_template_path. '  /'. $APP _template_file); Include_once (App_template_path. ' /footer.php ');?


God, just looking at the code will give me the urge to retreat. The concept of this code is to make sure that every application is suitable for this process, such as I can simply copy the template.txt into the myapp.php, change some variables, and see, it will work. Nonetheless, there are some serious drawbacks to this tightly organized approach:

What if my boss wants the author to use myapp.php to output PDFs in some cases, output HTML in some cases, and some cases (XML requests that are submitted directly) SOAP?

What should I do if this application requires IMAP or LDAP authentication?

How do I handle various different codes (including editing, upgrading, and deleting)?

How do I handle multi-level Authentication (admin vs. non-admin)?
How do I enable output caching? Www.phpv.net Reprint please indicate the source

"New Way"

Throw everything into this MVC framework and you'll find that life is so simple. Please compare the following code:

  

Note that this code is clearly not used to link to a database, to determine whether a user has logged in, or to output any other information. The controller has mastered everything.

If I want to verify LDAP, I can build Fr_auth_ldap. The controller can identify certain output methods (such as $_get[' output ') and can be converted to PDF or soap at any time. Event handling Delete, which is only responsible for the deletion, the rest of it does not matter. Because this module has an instance of the Fr_user class, it can simply determine if a user has logged in and so on. Smarty, controlling caching as a template engine is a matter of course, but a controller can also control a subset of caches.

The old way from the front to the MVC approach may be a new and unfamiliar concept for many people, but once you switch to such a concept, it can be quite difficult to turn back.

  • 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.