Start your MVC with PHP (d) Implement the view layer

Source: Internet
Author: User

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
<

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.