The main task of the view layer of the MVC pattern is to work with the display of the page and the results. In the implementation of PHP, mainly reflected as a template (using templates, you can achieve the PHP code and HTML code separation purposes, so that the code and the maintenance of the page more convenient, easy to manage and the replacement of the page, Can really divide the programmer, the Art of Division of Labor) parsing process:
First, the controler layer gets the data from the model layer
Second, the controler layer gives the data to the view layer
Again, the view layer interface passes the data to the template parsing class in a certain way,
Finally, the template parsing class parses the data into the template and then displays it.
The following is a concrete implementation example
Directory structure
| | classrendertest.php & nbsp; //Test Resolution classlist.html | studentrendertest.php // Test Resolution studentlist.html | | render/templateparser.php //Template Resolution Class |-render/render.php //parsing the base class for all classes of the template | | render/studentrender.php // Parsing template studentlist.html Class | | render/classrender.php //parsing template classlist.html Class | | template /studentlist.html //template file | | template/classlist.html //template file |
Attention:
1, here template parsing class selected a simple "templateparser.php", according to individual needs you can choose any kind of template parsing class;
2, if each template parsing directly calls "templateparser.php", there may be a large number of duplicate code appears, this is not permitted by OO thought. Therefore, the "render.php" is used to package it, and then the Render class in "render.php" is extended to analyze the different file templates.
3, different templates to resolve the class, the use of different methods, their packaging may also be different.
4, "studentrender.php" "classrender.php" is packaged render class, respectively, to meet the resolution of "studentlist.html" "classlist.html" needs.
File 1:classlist.html
Current: _now_ <BR><BR> Current School Class list: <table border=1> <TR> <TH>ID</TH> <TH>NAME</TH> <TH>GRADE</TH> <TH>CLASS</TH> </TR> Begin_classlist_ <TR> <TD>_cid_</TD> <TD>_cname_</TD> <TD>_grade_</TD> &nb |