Understand the MVC mode of ZendFramework. What is the ZendFrameworkMVC design pattern? The Model-View-Controller (MVC) mode refers to the Model-attempt-Controller mode. its core idea is to divide the entire program code into independent ones. what is the Zend Framework MVC design mode?
The Model-View-Controller (MVC) mode refers to the Model-attempt-Controller mode. its core idea is to divide the entire program code into three components that are relatively independent and can work collaboratively, the specific functions are as follows:
- Controller: control layer. To control the entire business process, and realize the collaboration between the View layer and the Model layer.
- Model: data business logic layer. Implements specific business logic and status management functions.
- View: presentation layer. It is a page for interaction with users. Generally, the data input and output functions are implemented.
In layman's terms:
- Controller-functions (implementing algorithms and so on) that programmers compile programs ).
- Model-database experts manage data and design databases.
- View-the GUI designer designs the GUI.
In other words:
- Controller-provides a guiding role. it does not perform any specific data operations, and the database business logic is handed over to the Model for processing. in the Controller, it can only be called. For example, if you want to query data in a table, only Function Show (parameter) is called in the Controller. the specific Show (parameter) is implemented in the Model.
- Model-database experts perform data management and database design, and specific Show (parameter) implementation methods.
- View-the so-called art design.
This MVC design pattern is a bit like the fact that we are going to eat at a restaurant. When you go to a restaurant to eat, the process is like this. first you have to order food. you don't have to shout, it's just a slide of water, the waitress who buried the eight-loggings will be in front of you, "Sir, what do you want? ", Look at the recipe." Give me a whole dish of shredded fish and a bowl of rice. "" Okay, please wait. "Said the waiter trotting toward the kitchen," That's what... Tell the cook not to put ginger in it !~~ "... The waiter will bring you the food you want. "Please use it slowly ~~ Call me for help. "You did not even wash the green peppers in them ~~~
In this simple process, you can use MVC to describe it. you are equivalent to View, the waiter is equivalent to Controller, and the damn Cook who does not wash green peppers is Model. When you first order food with the waiter, it is equivalent to sending a request to the server from our browser. the waiter delivers the food you want to eat to the cook, it is equivalent to the control layer handing over the requests sent by the browser to the business logic layer for processing, and it doesn't matter how the cook makes this dish at all. anyway, you can give me a dish of shredded fish, it's his business to wash green peppers without washing them. this is the "encapsulation" We often hear from the old bird's mouth. it's a good package. you can enjoy the fragrant smell of fish-flavored shredded pork that you don't even wash green peppers ~~ When the waiter puts a hot fish shredded meat in front of you, it is equivalent to sending it back to the browser after the business logic layer completes processing, and then display it to the user through the browser. In this way, a simple MVC coordination interaction is implemented, and you do not know what it is...
Let's use a simple login module. the requirement is that you enter a user name and password. if the input is the same as the predefined one, the correct page is displayed. if the input is different, an error message is displayed. "You are not here to contact me. entered incorrect! ".
In this small module, the page for entering the user name and password at the beginning is similar to the page displayed after verification, and here a Controller page is required to receive the entered user name and password, there is also a Flg returned after verification (this Flg is used to determine whether your input is correct and jump to the corresponding page), and a Model is missing, then you are the class used for verification. it is used to process whether your input is the same as the predefined one, and then returns a Flg. In this way, the separation of logic and page is completely realized. no matter how neat the page is, I will display it, and the Controller does not care whether your Model is correct, I gave you the username and password, and you have to give me a Flg, just like the waiter, no matter whether the cook or the green peppers are washed, but what about Medol, if you dare to give me a user name and password, I will give you a Flg ~~ If you see this, you are a little confused. you can try it later !!
Currently, when developing WEB applications, one of the most popular practices is to use the "MVC" structure to develop WEB applications in this way, which is logical and simple, it makes program design more convenient and convenient. What is "MVC? Simply put, it is a combination of "Model", "View", and "Controller", that is, all the three-layer abstract structures, of course, the "MVC" mentioned here is for WEB applications. "separating code from page design" is the dominant idea, this idea is fully embodied in the "Struts" using JavaServlet/JavaServerPages technology. if you are interested, you can go to Http: // Jakarta. apache. look at Org/Struts. this design mode enables program designers to focus on code design, writing, and debugging, web designers can spend more time designing and ignore the implementation of specific functions. this division of labor is fully applicable to large-scale projects or enterprise-level distributed application development.
From the introduction of PHP5, we can see that the object-oriented functions are becoming more and more perfect. using PHP to develop large commercial websites or distributed enterprise applications has become possible. if Zend Optimizer is used together, code Encapsulation has been implemented.
How to develop WEB applications using the "MVC" design pattern in PHP? Remember one thing (separate code from page design) and use a simple example to demonstrate it. for example, if you want to query member information from the database to display on the webpage, you need to consider two points here: 1. connect to the database and retrieve the member information. display member information on the webpage. connect to the database and use a database class. Call it a "DB" class. This Class assumes the role of a "Model) "role, then we need to write a program that operates the" DB "class to retrieve data. The role of this program is" Controller )", it accepts the "POST" or "PUT" data from the client, then calls the "DB" class to retrieve the data, and stores the data in "Controller, finally, pass the data to "View" and display the data in a certain typographical format. from the analysis above, we can see that the template plays the role of "View" here) "role, of course, only one template class cannot be said to be MVC. The real MVC is not so simple. for details, refer to" JSF ".
Protocol Framework MVC design pattern? MVC (Model-View-Controller) mode, that is, Model-attempt-Controller mode, the core idea is to divide the entire program code into relatively independent and...