Describes the functions of PHP templates in detail.

Source: Internet
Author: User
Tags php template what php smarty template

LearningPHPLanguage, we found that the knowledge about PHP templates is a little difficult to grasp. Today, we will give you a detailed analysis of the specific functions of the PHP template to deepen your understanding of the PHP language.

In fact, the most important thing is to suit your project needs, rather than your habits. for example, an enterprise's publicity website has a small access volume and a small amount of updates. It uses the same content and even does not need to be used. Direct PHP + HTML writing may be the fastest. there is nothing to do. however, if it is a news system or a content publishing system. in this way, it is very necessary to use the template technology. because they all have a common place, that is, there is a type of page that needs to use the same style of page design. depending on the actual situation, such as the traffic volume, project urgency, and programmer's proficiency in template technology, select the template technology that best suits the project .. this is the first choice."

"Since learning php, I started to use templates. I used the smarty template engine (officially supported and powerful). The longer I used it, the more I thought it was a good thing. As long as the page display is involved, I will use the template to write the content. If I do not use the template to write the program, I always feel awkward. I think other phper will share the same feeling, because the PHP template is designed to separate the code and page for processing separately. After all, no one is willing to write code while processing the page."

"Some people say that SMARTY is good, but some people also say that SUPERTPL is better, and some people prefer PHPLIB. I think each template has its own advantages and its own advantages, the key is what your project needs and what is best to use!" [From feifengxlq] "It must be correct to use a template. PHPLIB was initially used. After using it for a while, it was too simple. Every template variable should be replaced by code, every time you reference a template, you also need to write a line of code (maybe PHPLIB has the batch processing function, I don't know about it), so I gave up. Later, when I used plog to build a site, I came into contact with smarty, it seems that smarty is too large to speed up the development process, but many functions are not actually used. Therefore, I wrote the template engine myself. The template implementation function is very simple, is the replacement function of a template variable, plus the include other templates and the foreach block operation function."

"I still use PHPLIB, but I will write some functions or classes based on my own experience and needs to encapsulate some of the most commonly used processing for template output ." [From seraph] "I am tired of using my PHP template and writing template parsing code. I chose to use an existing good template ." [From Bantu] "I have seen some amazing people on other forums without using templates... maybe it's not that realm... I personally think it is better to use the template .. at least division of labor .. accelerate development. Use your own template? I don't feel it is necessary to use the ready-made functions. I just need to add some practical functions that I want to learn ." [From phonics] "I don't use the template engine, but I also use templates, but they are different from yours. It is difficult to use the template engine because it is too slow ."

"I use a third party, preferably open source. ." [From leeyupeng] "I prefer to use my own template for simplicity and practicality ." [From sunset] "considering performance, I generally do not use general templates. I will make some trade-offs based on the actual situation, which has certain limitations ." [From Ben] "decide whether to use the template or what template to use as needed. There is always no harm in flexibility ." [From xlmo] "I personally like simple and fast templates. You can consider using ready-made PHP templates. However, some functions that are not used in these templates are usually optimized based on the actual project ."

The use of templates generally does not lead to bottlenecks. As for the impact points, the efficiency is mainly as follows:

1. After the program and template are separated, one file will become two or more. Reading the template IO is also the key time.

2. parsing templates are relatively complicated. Generally, N functions such as preg_match and preg_replace are required to process or replace

3. The loading and replacement of the template obviously requires more memory than the template is not used.

To improve efficiency, pay attention to the following points:

1. The template parser supports compilation and caching. This is the most obvious benefit to the performance and depends on how you can flexibly apply it.

2. The parsing program should be as simple as possible. It is convenient to put all the functions into use, and the performance is poor.

3. html template pages follow simple principles, such as the xhtml standard. Try not to split a page into many templates and then include them ."

"If a template is used, I think it is better to write it by myself. This is also an exercise. But I think Xiaoqiang is good. You can edit it in a visual manner ." [From jejwe] "I personally think that visual editing of template files is very important. It is not required that the creation of the template page should also have a fairly basic program development ." [From seraph] "for specific analysis of specific problems, whether to use PHP templates or not, select an excellent template class that has been formed or write it by yourself. Everything depends on the specific project development, you cannot find one." [From Deepseath] "I feel that the existing templates are not perfect, either with few functions or slow speed, or I am doing well ."

"In summary, the PHP template can make your code context clearer and the structure more rational. However, the development of PHP templates will always be much slower than the rapid development of PHP applications. In this case, it will affect the development of PHP applications. For every PHPer, no PHP template is the most suitable and perfect for him. Because the so-called PHP template is popular, it is not for individuals.

Therefore, if you can fully understand the advantages and disadvantages of the template and the principles of the PHP application on the basis of a clear understanding of PHP features and applications, PHPer can get the PHP template that suits your development style. This is also one of the most important ideas of PHP. PHP only provides methods, approaches, rather than final solutions. Therefore, templates can be transformed into their own PHP templates like PHP applications and products. This is because the idea of the Creator is pinned on it.

Due to various restrictions, such as time and experience, you may think it is very difficult to create your own PHP template. In fact, what you need is not to re-construct a PHP template, but to select a PHP template that is closest to you. Because PHP needs to inherit and innovate. Of course, make your own PHP template step by step, and integrate the latest ideas and ideas in a timely manner.

Personal PHPer can start from the details, from the places they need most and Their Development habits. The PHPer team can work collaboratively to localize PHP templates, especially for companies. Even if you have modified a symbol in the PHP template, it only indicates that you have modified it. It belongs to you. The most important thing is that your PHP template will never remain unchanged. It will grow with you and become a witness to your PHP history.

PHP does not require a very proficient syntax. PHP does not require you to develop many libraries on your own. PHP does not require you to worry about the features of languages such as performance and stability. What PHP needs is your logic; what PHP needs is your creativity; what PHP needs is your thoughts !"


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.