Choose the most suitable template in the PHP world - Compare phpo Template and FastTemplate

xiaoxiao2021-03-06  123

Choose the most suitable template in the PHP world - Compare phpo Template and FastTemplate

The template application in the PHP project is a good approach to the processing performance layer recommended in medium and even large projects. However, the implementation of the formulation of the template, but it needs to be compared.

Template processing in PHP world has two kinds of phpLib Template and FastTemplate. We evaluate the ease and speed of technology - want to know the results? What is the cause of things: Do you have used fastTemplate? For template applications in PHP projects, in fact, I have already touched in many projects - about it, I think there is a lot of angles in the actual development stage or rising to design patterns. " The predecessors are discussed. For project implementation, in some medium and even large projects, it is effective to separate HTML (and other text forms) and PHP code, but not only improve interface designers and applications, not only in the development stage. Work efficiency will bring huge convenience to the test and maintenance of the project. However - the purpose of this article is not to discuss the advantages and disadvantages of the template, nor is it as a guided tutorial to teach how to use the template in the PHP project, but compare the most popular template processing mode in both PHP world in the application perspective (in fact However, there are two templates classes): phpLib Template and FastTemplate. In fact, I have been using phplib template in "quiet". It is very stable and it seems to look at the speed. I don't want to go any more alternatives - Although I also know this earth There is something like fastTemplate (and also in the world of Perl). Until one day, there was a colleague asked me: "I don't know how fastTemplate? Why don't we try fastTemplate?" "Well, let us try!" But as a steady method, in any new mode or Methods Before introducing projects, it is best to understand it more comprehensive, and find one or a few reasons to adopt it to adopt it - for fastTemplate is no exception. The protagonist appearance: Learn the phpLib Template and FastTemplate I have already said, I have already used phplib for a while - I think you may be like me before the screen, and I have a deep thing to this excellent tool class! Similarly, when I start to seek a template solution, I naturally searched in the toolbox closest to the side, so I found the Template class in phplib. After the initial browsing of the API it provided (Of course, I would like to thank the PHPLIB detailed document), I started using its history - until now. FastTemplate seems to be more famous, and in the Perl world of its hurt, it seems to be in the PHP world. It is enough to believe in its ability to believe in just this. Regarding the use of the two, I would like to have more nonsense here; but after all, I feel that I am afraid I have written two tutorials. There is no existing tutorial. Welcome - In this article, there is phplib Template And FastTemplate's famous tutorial, if you have not had no one to know about these two templates, I suggest you go to see the two articles, you should get a lot of beneficial template application knowledge. (A mouse click and the eyeball is finished and even personally prepared test code.) Now you have some understanding of the two templates, maybe I have discovered a lot of similarities between them, I will summarize these places. a bit.

The setting of the variable is obvious, the form of {foo} or {bar} is specified in the two templates; that is, in the two template processing methods, the appearance of the template file itself should be consistent (for example The HTML file contains a variable that will be replaced with {} identifies. The initialization of the template class (class builder) requires the directory location where the template file exists when building a template class. The most commonly used variables is the most commonly used variable replacement. In addition to the method names (PHPLIB Template uses set_var (), FastTemplate uses assign ()), and the usage is almost consistent - can be used (KEY, Value's way, you can also pass an array directly (Array (Key => Value). The processing of the template file is a way to specify a handle (Handler) for each template file, and the handle can also replace the variables in another template file as the value of the variable. Analysis, the output process is needed to call the parse () method (this method name is actually the same) to assign the template file that needs to be output to a handle, then call the respective output (P () in phplib template, fastTemplate The content of the handle is output and the processing is over processing it is FastPrint ()). Repeated resolution, such as removing several records from the database requires display, and the template file is only available to the alternative line variable, it is necessary to function. Both have such a function, just slightly different (phpLib Template), and fastTemplate uses PARSE (Handler, .Value) to add a point in front of the value, you should say phplib The method of Template is constructed relatively beautiful. The process of block parsing (or can be called dynamic analysis) Imagine that you need to take out the eligible data from the database and display it in the web page - but because the conditions will not be the same, you can't clear how many Data - This time if you need to use a template, the block is the best choice. It is a portion defined in a template with a particular symbol, which can be repeatedly parsed and added to (not the previous resolution by the last overlay) Output web page. The block may be like the same display (the left side is the block settings used by phpLib Template, and the right side is FastTemplate): Ok, if you introduce the above pale text, you can't touch it, then we come Take a look at the two detailed template processing routines! (If you are interested in discovering the test code behind, you will find that the following two examples come from there.), Is it almost consistent? Below is an example of block parsing, you will also find the same effect: our test objectives and results have ended the understanding of phpLib Template and fastTemplate, which should be able to enter this article - Of course, it should be easy to use in the application environment. At the same time, the ideal component building system is constructed, so it is necessary to evaluate the evaluation for such two similar techniques. The evaluation should be composed of two parts: the difficulty of the technology is difficult and the speed of the speed - the former is part of the comment, and the latter is a part of the test. For the former, we mainly review the API provided by the two classes; for the latter, we will let the test data to speak, of course, this is from need to write some simple test code.

Round 1: The ease of technology This round is mainly to explore the usage of the API provided by PHPLIB Template and FastTemplate. It should be said that the API provided by the former is more in line with some of the common coding practices of PHP (especially when using other classes in your project, this normative will have a good impact on the entire project); while some of the methods The name always feels some awkward (I hope you don't think this is my narrow view, such as fastprint (), etc.), and the parameters of the method are not very "authentic", this can also be seen from the code just now. Another point needs to be pointed out that for the parsing of the template block, FastTemplate has begun to support until the nearest release. That is, if you use the previous version, you have to store this content independently in somewhere in handling the output, such as the output recorded in the database, and then add this file when the template analysis is processed - it is one The uncomfortable thing, especially for web designers. Of course, there is still a point in view - that is the support for PHP versions. PHPLIB is generated in the era of php3, this and fastTemplate is almost; but according to our app, phplib is quite good in the current PHP4 environment, and some information shows some information on PHP4, there are some bugs . Ok, talk so much (maybe you will feel the bad words of fastTemplate), the winner of this round is obvious: phpLib Template, especially when you use the phplib's other classes, such techniques are more obvious (You will not feel unfamiliar with these APIs from the same development group). Round 2: Processing speed Maybe this is the most concerned part of many people - in this round, we will use two template processing: one is a routine analysis, replacement, and the other is the analysis of blocks. , Alternative - simultaneous two ways also apply the most in the actual system: the former is a general page processing, the latter is the output processing of the database content. At the same time, since the format of the template files used in the two templates is basically the same, we can provide almost consistent template files for two template resolution, more increased the credibility of the test. A test scheme is prepared before the speed test is carried out, and it is to be written in two PHP test pages. At the same time, there is a control test page multiple calling these two pages and recording time for acquisition test data. . (If you are interested, you can also refer to the following detailed test programs, maybe you will understand this test.) Summary - After the entire test system is completed, we should be able to get the following file list in / Test directory:

(A bit complex test plan) first is determined to determine the hardware and software environment of the test - hardware is definitely its own machine, Intel Celeron 733MHz, 256M RAM, 40G HDD; Software Platform OS is Win2k Pro, the web server is Apache PHP And run in a module. Secondly, the system plans this test - Of course, first open a TPL_TEST new directory in the Web server's document root directory to place all files for this test; then build the include directory in / tpl_test to store two template files (We tested the core, in .inc.php is the file extension) and a test class file (including timing and logging logs, and reading logs and analysis, etc., with .inc.php as file extension) and a data Document (preparing for the test for block parsing, mainly including a two-dimensional array, equivalent to .inc.php as a file extension), establish the template file (template file that needs to be parsed by .ihtml) For the file extension), establish the log generated by the logs directory storage test (later, it is found that the data of the test is obtained by the analysis of these logs, with .log as the file extension). Of course, the processing PHP files of the two templates are placed in the / Test directory. The most critical point of this test is that a PHP file is also needed, and the file that is mentioned above is called several times. For example, a file fast_test.php is a FastTemplate parsing template, and phplib_test.php is adopted PHPLIB Template parsed, then the PHP file that the result is responsible for requesting the above two pages in HTTP to obtain test data. Select the template and PHP program to be parsed - because the two template processing methods are almost consistent for the format of the template file itself (such as the form of {var}, etc.), so it can guarantee two in the same test. The selected template is as the maximum fairness of testing as much as possible; at the same time, the two templates commonly used in the simulation of the real system: the general page processing and the output processing of the database content, the test used template file It is also divided into two: one is a template file with some template files to be replaced, the other is a template file that requires repeated replacement of the content that should be output. The same is required for both template files, and two different PHP files are needed. Test Method - Request to / Test/Result.php in the browser, need to be tied with parameter type = [simple | complex], you can see the test results in simple or complex mode in the result of the result of the returned result. .

Level 1LVEL 2LEVEL 3REMARK / TEST Test System Root Record Result.php Tests and generates a PHP file for results. You only need to request this page in the browser when the test information is requested. PHP file Simple__test_fast.php Using FastTemplate PHP file complex__test_phplib.php using PHPLIB Template to analyze PHP files with block templates complex__test_fast.php using FastTemplate PHP file / include PHP class file .inc.php phpLibTemplate.inc.phpphplib Template class file fasttemplate.inc.phpfastTemplate.inc.phpfastTemplate class file TPLTest.inc.PHP test requires the test class, including timing, read / analysis log, etc. Data.inc.php The data file used when the block template is tested. Usually the template file simple_fast.ihtml / ihtml containing the template file using PHPLIB Template .ihtml simple_phplib.ihtml FastTemplate process using the template file is generally treated using PHPLIB Template complex_phplib.ihtml band processing block using template file complex_fast.ihtml treated with FastTemplate Block template file / logs contain log files .log simple_phplib.log uses phplib template to process a log Simple_fast.log generated by a PHPLIB Template to generate a log complex_phplib.log using a pHPLIB Template Processing Zone Template Generated Logs COMPLEX_FAST .log uses the logs generated by the FastTemplate Processing Zun Template. After the test system is designed and written, and we can visit this system after discussing colleagues responsible for web design, we can visit this system - the previous hard work makes it now Working with the results only need to be http: //localhost/tpl_test/result.php? Type = [simple | complex] in the browser's address bar, if you do this in other non-local servers, then The domain name should be used to use the domain name of the server - such as my own machine called Patrick, etc.). Here is the result I have obtained in a certain test: (Explanation of test results)

Name Interpretation Remarks Amount Total (Continuous Request This Page Total) This parameter can modify the maximum processing time of Max_SEQ maximum processing time in the Result.php file, the maximum peak data for the max_value maximum processing time in 1-Amount For reference minimum processing time The serial number range of 1-AMOUNT Min_Value minimum processing time value peak data for reference for the most valuable data in the Average average processing time test, if you think that the results of the test are unreliable, you can press the browser repeatedly The refresh button can observe the results of different tests (theoretical should be different). The test results and the "XX Selection Award" are good, and PHPLIB Template has struck fastTemplate in the rounded secondary speed of the bias speed test; while the phplib template in the first round has a good API design and easy Use sex to top the wind. The results are obvious - our choice awards have been issued to PHPLIB Template, and this test also makes us understand the PHPLIB's library design. Subjective evaluation Since there is a result, FastTemplate naturally can't enter our project. Although we have spent half a day from the results, it has been a variable result (phplib template continues to be in the project. Use it), but the process of testing is very valuable, especially the method of testing using PHP, should play a certain reference role in future similar decisions. Reference information This article downloads (Article_256.zip) Introducing the famous articles of PhPlib Template and FastTemplate Templates, The phplib Wayby David Orr, May Of 2000 (http://www.phpbuilder.com/columns/david20000512.php3) PHPLIB Template) Templates - why and how to use them in PHP3by Sascha Schumann, March of 1999 (http://www.phpbuilder.com/columns/sascha19990316.php3) (FastTemplate) PHPLIB Template and FastTemplate homepage

PHP Library HomePage (http://phplib.netuse.de) fastTemplate HomePage (http://www.thewebmaster.com Other Template Processing Articles and other information about PHP PHP Builder (http: // Www.phpbuilder.com) Chinese translation above the article and other Chinese PHP Information PHP Chinese users (http://phpuser.com)

About the author Wang Chen, a web developer, and is interested in writing and translating articles related to their own technology hobbies (more like others call yourself patrick when work and publishing articles). I have focused on PHP, and now there is more hobby lies in Java; it is also one of the advocators of Open Source. I often like to visit the bookstore when I am leisure; I often move around the home and near the alma mater - graduated from Southeast University. You can contact him by email patrickwang@163.com.

转载请注明原文地址:https://www.9cbs.com/read-126631.html

New Post(0)