Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of PHP tag template technology?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What is the principle of PHP tag template technology? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

There will be some misunderstandings in our understanding of the PHP tag template, because it is a difficult technology to master. So, we hope that through the introduction of this article, we can initially grasp the principle of PHP tag template technology.

1. The origin of the template

Before there was no template technology, PHP was used to develop programs, usually a mix of php code and html. For example, the news list is probably a newslist.php page with the following structure:

…… ..

So what's wrong with this? First of all, it is not conducive to the division of labor and cooperation. Generally speaking, programmers write the code and artists design the page. So in this way, the programmer must wait for the artist to design the interface before starting to work. In other words, the work of programmers and artists cannot be synchronized. Secondly, it is not conducive to maintenance and poor maintainability. For example, after the program is fixed, if you want to modify the interface, it must be modified by the artist and then re-added by the programmer. The structure of the program is chaotic and the readability is poor. HTML and PHP are mixed together, and once there are too many programs, they will become very messy.

Understand the principle of templates-use PHP tag templates

Template technology is to solve these problems, in order to solve these problems, the earliest emergence is the use of PHP tag template.

First of all, we need to understand the purpose of the template. How many tasks does the template have to implement?

The separation of *, art and program. More accurately, it is the separation of acquisition data and display data.

Second, the division of labor. Good division of labor.

For example, if we use the PHP tag template, we can divide the operation of the news list into two parts:

1. Getnews.php is responsible for reading data from the database into the array $news, regardless of how $news is displayed.

2. Shownews.php is responsible for outputting the $news array into a HTML page. And it doesn't care where $news comes from.

Well, in this way, we have achieved the separation of the artist and the program, and achieved our initial goal, but how to combine the two pages and achieve the function of listnews.php?

This requires another page, listnews.php, to connect the "artist (display data)" and the "programmer (get data)". We should say that this page is very simple.

Suppose the code for getnews.php is as follows:

< ? $news ="新闻列表";//实际中应该是从数据库中读取出来的。 ?>

The code for Shownesw.php is as follows:

< html>

< head>

< title>

Show news

< /title>

< /head>

< body>

< ?=$news?>

< /body>

< /html>

So, the code for this federated page listnews.php is very simple.

< ? Include(‘getnews.php');//获取数据 Include(‘shownesw.php');//显示数据 ?>

Summary

The use of PHP tag template system can achieve a good separation of artists and programs, and facilitate the division of work and cooperation between programmers and artists. For example, in the above example, shownews.php is maintained by American workers and getnews.php is maintained by programmers. The listnews.php can be maintained by the system designer. Of course, some agreed documents need to be added in the middle.

In fact, this simple example also illustrates the most basic MVC model. Where M, the model, that is, responsible for reading data, is equivalent to our getnews.php. V, which is an attempt to display data, corresponds to shownews.php. * is controller C, corresponding to our listnews.php

The answer to the question about the principle of PHP tag template technology is shared here, I hope the above content can be of some help to everyone, if you still have a lot of doubts to be solved, you can follow the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report