Use PHP to start your MVC (4) Implementation of the View layer-PHP source code

Source: Internet
Author: User
Ec (2); the main task of the view layer in MVC mode is to display pages and results. In php implementation, it is mainly embodied as a template (using a template, php code and html code separation can be achieved, so that code and page maintenance is much more convenient, easy to manage and page replacement, can truly divide the division of labor of programmers and artists) parsing process: first, the controler layer obtains data from the model layer. Second, the controler layer submits the data to the view layer. script ec (2); script

The main task of the view layer in MVC mode is to display pages and results. In php implementation, it is mainly reflected as a template (using a template, php code and html code separation can be achieved, so that code and page maintenance is much more convenient, easy to manage and page replacement, can truly divide the division of labor of programmers and artists) parsing process:
First, the controler layer obtains data from the model layer.
Second, the controler layer delivers the data to the view layer.
Thirdly, the view layer interface transmits data to the template parsing class in a certain way,
Finally, the template parsing class parses the data to the template and then displays it.


The following is an example.
Directory structure
|-ClassRenderTest. php // test classlist.html
|-StudentRenderTest. php // test studentlist.html
|-Render/TemplateParser. php // template parsing class
|-Render/Render. php // parse the basic classes of all classes in the template
|-Render/StudentRender. php // the class of the intent template studentlist.html
|-Render/ClassRender. php // the class of the callback template classlist.html
|-Template/studentlist.html // template File
|-Template/classlist.html // template File

Note:
1. The template parsing class uses the simple "TemplateParser. php". You can select any template parsing Class Based on your needs;
2. If "TemplateParser. php" is directly called for parsing every template, a large number of repeated code may appear, which is not allowed by oo ideas. Therefore, "Render. php" is used to pack it, and then the Render class in "Render. php" is extended to parse different file templates;
3. Different template parsing classes use different methods and their packaging methods may be different.
Required.


File 1: classlist.html

Current time is: _ now _


Current school class list:












BEGIN_classlist _ & Nb
ID NAME GRADE CLASS
_ Cid _ _ Cname _ _ Grade _

<

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.