Understanding the MVC pattern of the Zend Framework _php Tutorial

Source: Internet
Author: User
Tags zend framework
What exactly is the Zend Framework MVC design pattern?

The core idea of the MVC (Model-view-controller) pattern, the model-attempt-controller pattern, is to divide the entire program code into 3 components that are relatively independent and work together, with the following functions:

    • Controller: the control layer. Play the role of controlling the whole business process, and realize the collaborative work between view layer and model layer.
    • Model: Data business logic layer. Implementation of the specific business logic, state management functions.
    • View: Presentation layer. is the page that interacts with the user, usually realizes the input and output function of the data.

In Layman's words:

    • Controller-The function that programmers write programs (implementation algorithms, and so on).
    • Model-database expert for data management and database design.
    • View-Interface designer for graphical interface design.

In a more popular sense:

    • Controller-acting as a direction guide, it does not perform any data-specific operations, the database business logic is given to the model to process, only call in the controller can be. For example, if I want to query the data in a table, only the function show (parameter) is called in the controller, and the specific show (parameter) is implemented in model.
    • Model-database expert for data management and database design, specific show (parameter) implementation method.
    • View-not to speak, is what we call the art design.

This MVC design pattern is a bit like the reality of the way we go to restaurants to eat. When you go to a restaurant to eat, the process is like this, first you have to order Ah, do not shout, a guangliu water slippery, buried eight of the small waiter will be the entire small before you, "Sir, what do you want to order?" "You look at the recipe," Give me the whole small plate of fish fragrant shredded pork, plus a bowl of rice. "Well, sir, wait a minute." "Say the waiter a trot toward the back of the kitchen direction," that what ... Tell the chef not to put Ginger! ~ ~ "... Take a moment, the waiter will give you the food you want to bring up, "Sir please slow use ~ ~ have what need help, despite shouting me." "You eat the wolf, do not know the inside of the green pepper mom did not wash ~ ~ ~ ~

Just such a simple begging process you can use MVC to describe it, you are equivalent to the view, the waiter is equivalent to the controller, and the one who does not wash the pepper of the Damned chef is model. You start with the waiter order, the equivalent of our browser to the server to make a request, the waiter will you want to eat the dishes to the chef, the equivalent of the control layer will be sent to the browser request to the business logic layer to deal with, and it no matter how the chef does this dish, anyway you can give me a plate of fish fragrant shredded pork, It's his business to wash the green pepper. This is what we often hear from the mouth of the "package", packaging good ah, sealed you even the green pepper did not wash the fish fragrant pork can eat perfume, hehe ~ ~ When the waiter put a plate of hot fish fragrant shredded pork end to you in front of the process, equivalent to the business logic layer after processing the corresponding back to the browser, It is then displayed to the user through the browser. This enables a simple MVC coordination interaction, and I don't know if you understand the point ...

Take a simple login module said, the requirement is that you enter a user name, password, if the input is the same as pre-defined, then go to the correct page, if not the same, prompted an error message "You y don't put me here, the wrong input!" "。

In this small module, the beginning of the user name password to enter the page with a verified page is the same as the view, and here also need a controller page, is used to receive input user name password, There is a FLG returned after the calibration (this FLG is used to determine whether you entered the correct, and jump to the corresponding page), and finally missing a model, then you are the class used for verification, he is to deal with your input is the same as pre-ordered, and then return to a FLG. This completely realizes the separation between the logic and the page, my page no matter what you do, I will be a display, and controller also regardless of your model how to judge right, anyway, I gave you the user name and password, you have to give me the whole back a flg come, with the waiter at all regardless of chef green pepper Wash does not wash, And Medol, it is anyway you dare to give me a user name and password, I will give you the whole past a flg~~ if you see this is a little enlightened, and then test to write it!!

Now in the development of Web applications, a more popular approach is to use the "MVC" structure, the use of such a way to develop Web applications, logic strong, Jianho clear, making programming easier and faster. What is "MVC"? Simply put, it is the "model", "View" and "controller" of the Union, that is, all the "three-layer" abstract structure, of course, the "MVC" here is for the Web application, "Make code and page design separate" Is its dominant thought, this thought in the use of Javaservlet/javaserverpages technology "Struts" performance of the incisively and vividly, interested can go to Http://Jakarta.Apache.Org/Struts to see, This design pattern enables the program designer to focus on the design, writing, and debugging of the Code, and the Web designer can devote more time to the design without regard to the specific functional implementation, which is fully adaptable to large-scale projects or enterprise-class distributed application development.

From the launch of PHP5 can be seen, which the object-oriented function is becoming more and more perfect, using PHP to develop large-scale commercial web sites or distributed enterprise applications has become possible, if combined with Zend Optimizer, has achieved the encapsulation of the code.

How do I use the "MVC" design pattern in PHP to develop Web applications? Remember a bit (Code and page design separate), with a simple example to illustrate, such as to query the database from the member's data to display on the page, Here are two points to consider: 1. Connect to the database and take out the membership information, 2. Connect the database to the Web page, link the databases we use a database class, call it the "DB" class, this class now plays the role of "model", then we need to write an operation "DB" Class of the program to take out the data, the role of the program is "Controller", which accepts the client "POST" or "PUT" data, and then call the "DB" class to take out the data, the data are stored in the "controller", Finally, the data to the "view" and in accordance with a certain format display, from the above analysis can be seen, the template here is playing "view" role, of course, just a template class can not be said to be MVC, the real MVC is not so simple, specifically can refer to "JSF".

http://www.bkjia.com/PHPjc/752463.html www.bkjia.com true http://www.bkjia.com/PHPjc/752463.html techarticle What exactly is the Zend Framework MVC design pattern? The core idea of the MVC (Model-view-controller) pattern, the model-attempt-controller pattern, is to divide the entire program code into relatively independent and ...

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