(Walter.fan compiled from Jason E. SWEAT written by An Introduction to MVC Using PHP)
MVC today today, I am afraid it is the most famous one in the design model. For Website, it is a good architecture. The so-called MVC Model-View-Controller Model - View-Controller, is An object-oriented design pattern. MVC uses classes to logic (where is stored, which users are allowed to handle these data, how to deal with these data), indicate logic (how to represent data from the model) Place the entire process of the application in the view in the view in the controller.
PS. Design mode is the programmer's internal strength method. The Jiu Yin Zhenjing of the design mode is "Design Patterns" of the "Four Gang". There is a design pattern in PHP in http://www.phppattenrs.com. Introduction to the application.
Why use MVC? Because MVC is an excellent solution for Website. In Website, click on each page is the interaction of users and systems (input). Suppose you have some needs To maintain the status of the stored data and its display mode, the MVC mode is a schema that is very suitable in your application.
MVC mode focuses on three types of problems when establishing a scheme 1. Handling persistently saved data (database or file) 2. Processing the logical control process of the application, what is displayed to the user, allowing users to perform what action to perform on the data 3. Display information to users in the application
JSP / J2EE is compared to the application of MVC http://blog.9cbs.net/fanyamin/102481/r_phpmvc1.gif matures, there are very many experiences for us to learn, see the following website http: // java .sun.com / blueprints / patterns / MVC.htmlhttp: //java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/webtier/web-tier5.htmlhttp: //developer.java.sun.com/developer/onlineTraining/JSPIntro /contents.html#jspintro4
"Model 1" and "Model 2" MODEL 1 mentioned in JSP specification description: The model is encapsulated in the system, but the view is spread on different layouts, and there is no page process controller Model 2: Recommended way , The process control of the application by the controller object
There are many very exquisite MVC realization in the JSP / J2EE world, including Struts (http://jakarta.apache.org/struts/)
Model ModelModels is a component that implements business logic in the MVC application, while business logic is related to any PHP logic code model related to the information storage. The word is from the real world. It is similar to the rules and data models unique and persistence in the system. Data storage is derived. (For example, saving or retrieving data in a web request). Model can implement any techniques in Web development: database call, file processing, session management, web services, or other storage data means.
A design excellent model can be used by other applications in the web server. When you start to see the power of these package business logic, you will clearly realize that making a good model is a very useful habit, even if you No need for a full MVC architecture
For models with database table interaction, a separate table preferably has a associated class that will help us get the first point of the MVC benefit: Processing data in some persistent data storage, as long as you stick to the MVC framework, If the database table is changed, then we only need to check this corresponding model in the system is a typical example of the web application is user, visitors, shopping carts, catalog items, orders, headers, or articles in database-driven web applications. In the model, the model tends to be associated with a single data sheet, or some table (or view) that is closely coupled together. As a reasonable naming rule, the name of the model class can be similar to the name of the database table. I also tend to be Website Function write model class, such as a form of a plurality of pages, can have an associated model wizard.
The view view view is a component that represents the output to the user in the MVC application. The most common PHP application output is HTML, but the view is not limited to this. MVC application can also output XML, WML, plain text, images, mail or other content In the view, PHP has a wide range of applications, send data to your browser, implement template solutions, etc., the view creation model, use the model's method to get data and present it to the user. In the application, the view contains All required to convert binary data into the desired data representation format. For example, using the Code of the GD library drawing in the MVC is a view controller Controller controller is the core component of the MVC application, it must know the user HTTP request (or command line input parameters) to determine what views display, or generate other correspondingctions of the application. In short, the controller is the core component of any MVC project (mainly because models and views must be based on their nature Suitable for your app). Different projects have different policies to decide how to interact with the view and models. Interactions between these objects are the coupling of the system. If you use a configuration file (usually using XML-based files) to define them The relationship is the so-called "loose coupling". The opposite approach is to hard encode the application process in the system.
The following figure describes the practical conditions of various techniques for web development in three components of the MVC. For example, if your application contains a User model, and you have a "remember me" Function, you may want to send a cookie value to the client browser with the User model. We should assign this task to the controller via HTTP. And we may consider where to display an instance of a model indicating the view, go to the URL parameter Show which view. As a result, the view may access to get this information through $ _GET. (Connect from the HTTP connection from the controller to the view). We should not see cross-use use of these technologies between the view and models. In the model Never incorporate HTML, never include any database access function in the view. All the above practices violate the principle of separating the content and format, breaking the MVC mode, and limits the application's flexibility.
There are many PHP-based open source projects on the Internet ambivalencehttp: //amb.sourceforge.net/this project is a port of the Java Project Called
Maverick (http://mav.sourceforge.net/), Which Originatedas An Attempt to Simplify Struts.
Eocnehttp: //eocene.net/an MVC Framework with a goal to port to asp.net.
PHP.MVCHTTP: //www.phpmvc.net/a port of the java-based Jakarta Struts Framework
PHPPATTERNS () mvc2http://www.phpptterns.com/index.php/Article/articleview/19/1/the second the mvc pattern.
Phramehttp: //phrame.itsd.ttu.edu/another port of the struts framework.
Combined with Project Practice In general, both PHP-based MVC applications have two total process paths. See the first process path below is the user sends a request to obtain a specific view. The second process path is the user input content And update the data of the model
The first process path 1. The controller is responsible for explaining the request sent by the user in an HTTP GET. The request is determined which corresponding view. 2. Application process goes to the view, usual view needs to come from the model Data to display the response result .3. View requests get data from the model. The model is the only component that can access persistence data storage containers (database or files). 4. Model query data to persistent data storage containers 5. Model Gets data from persistent data storage containers 6. Model Returns data to the view If the view requires data in the current or other model, repeat the third step to sixth step 7. View format and send these outputs Give the user a response.