The template for PHP is indeed a thing that is easy to do. Just a number of more than 20 options, the light pear contains different templates in 5, which is really a headache. Don't say this is not good to say this good, and what should I first know before choosing a template? What is the true purpose of the template? Simply put, the core of the template is a TEAM WORK. There are two main ways: 1. Separation HTML and PHP make web designers and PHP programmers more enjoyable. 2. Separate display logic and things logic, making the core transaction logic change and application's extension easier and flexible, that is, cooperation between programmers is even more enjoyable. (This is often neglected or misunderstood, always thinking that PHP will make it out of HTML, it is called the separation display logic and things logic. If so, what does PHP and HTML make PHP and HTML?) Find this template's true purpose What is easy to make the right choice. If you only have a PHP programmer but need to work together with other web designers, you can choose the template that you can separate HTML and PHP, phplib (now seems to be integrated into pear http://pear.php.net / package / html_template_phplib) or fastTemplate is something like this, it is easy to get started. If your website interface is ugly and is mainly completed by programmers, but the function is more complicated and more powerful. You need to separate all levels including display logic, then don't use something special, PHP itself is the best template. . It should be noted that in this case, you have to design your program very seriously, always remember that it is not PHP and HTML to be separated, but the business logic and the display logic. This is why I have been very conflicted with smarty, because this Smarty's grammar is too complicated, almost reinvented a scripting language, (even PHP programmers must re-learn it). What is more puzzling is that this script is stronger, the easier it makes people mix the transaction logic and the display logic, and destroy the original intention of the template. If you want HTML and PHP separation, you get better visual design, and you want the entire system to have very powerful extension capabilities to adapt to HTML, XML, WML various interfaces, and don't have to learn complicated syntax. Running efficiency, then this is a fairly challenging problem. Bad news is that there is currently no mature template that really can achieve such a requirement. It is not very difficult to complete such a template. If you try Zope or ColdFusion will find this template, (Wact HTTP : //wact.sourceforge.net/ and phptal http://phptal.sourceforge.net/ is developing to this direction and should be promising). The combination of templates and data (template call) is mainly two ways: pushing methods and drawings. The way to push the data to the template with PHP, that is, the programmer is required to be assigned to each variable in the template, tie them. The way to pull is like mixing PHP and HTML, and the template variable actively puts the data.
It is not possible to mention the other two things: Phphtmllib and Quickform (http://pear.php.net/package/html_quickform) These two things are in traditional ways to complete HTML through various page components. The construct of the entire page of the page is completely in the hands of the programmer, maybe many programmers who have written traditional GUI desktop programs prefer this way. If you do a commercial software, Flash should be a more beautiful program (don't make a mistake, don't think you know that PHP supports Ming and SWF libraries to dynamically generate flash, I said it is not this.) I want to say It is a solution that supports Flash Remoting, which is a combination of PHP and Flash. The visual designer completes the flash section, and the PHP programmer sends the data to the client made by Flash Remoting. There are currently two options: AMFPHP http://www.amfphp.org/ Using Macromedia Flash Remoting Transport data is a unique more efficient data format, AMFPHP is constructed in the server side by analyzing the data format. The PHP class is received, resolved, and encodes these data to achieve the function of exchange information (just like Samba, should belong to a Hacking). PhpObject http://ghostwire.com/resources/phpobject/ phpObject The additional method is used to transmit data by an open format SOAP in Flash. In fact, the template for PHP also involves many other problems. I will only write so much in a short time. I have time I will write it. Your thoughts? Agree to the second floor. I usually don't have to use the so-called HTML template, and the transaction logic that is said to the second floor is separated from the representation logic. That is to say, the logic is displayed with a separate unit, and the transaction logic is encapsulated with OO, and some of the servlets similar to Java are separated from the JavaBean. At the same time, in order to cooperate with the web designer, then do the code and HTML separation, I use the second compilation template. That is, in the initial element, the resource file and the frame file, then the two files are first compiled, combined into a template file without code, modify this template file by web designers, this file contains a small amount of special Syntax tags, but not complicated, mainly variables and formats and small amounts and necessary process controls. After the designer is completed, the template is compiled, generating a PHP script of display logic, that is, compiling the template into a PHP script that can be used directly, and only the display. The transaction logic runs before the logic, usually only uses an instance of the class, and the variables in the display logic can be associated with transaction logic, in fact, here, the second floor said that the way is said, that is, in the display logic, The code is mixed with HTML, but the main function is the display interface, while transaction processing, such as taking data from the database, etc., is processed in the transaction layer. Just this last display logic generally doesn't have to write a PHP script yourself, but can be compiled directly from the template. This kind of drawing data is higher than the use of the push mode efficiency, because it does not need two parsers for the PHP interpreter (one is the script parsing template). In this way, it is generally necessary to generate a display logic, and it will be used directly, and it is not necessary to pay every time the template in the PEAR is in time.
With the secondary compilation method, it can also be highly scalable. There is only a pure constant in the resource file. There is only a pure structure in the structural document. The constants in the resource file can be changed into a variety of languages. The structural file can be unchanged. The first compilation and synthesis generation of real template files, it does not include any PHP syntax, only some put
The structural tag between the resource file is mixed with the HTML page of the string in the resource file. At this time, the web design person can be used to modify, after the modification, after the second compilation, directly generate the representation of the PHP script, then the script That is, the PHP code is mixed with the HTML code. I have planned the template, and I wrote such a few categories: ResourceLoader, blockprecompiler, blockcombiner, TemplateCompiler's first compilation of the structure file called Block, each block can be compiled separately, or compile together, compile, press main block. The structure will be included in the block combination to generate a template file - this file is a file for the modification of the web design, and of course modifies the first small block after the first compile, and then combines. The approximate process is: 1, first use ResourceLoader to transfer resources from the specified language package resource file, and resolve, generate a array in this class; It can also be compiled according to the case of the main entrance Block's file, and the existing compiled block can choose overwritten or reserved (manually, the class method does not automatically determine whether the file time is overwritten, because considering web designers You may modify the compiled block itself; 3. Use the BlockComBiner to include a combination of compiled blocks in accordance with the information in the primary Block entry file to generate a template file for modification of web design personnel. This class only combines, not compiled, unless the file containing the file has not been compiled, but the main entrance block must be precompiled, otherwise it will be wrong to exit. In summary, it is to ensure that these blocks are compiled at least once, and if the coverage is required to compile it. The generated template file does not contain a PHP code; Used for the process. This is mainly to consider the template modification is not so frequent, and the use template is very frequent, so the best way is to mix this inherent advantage directly with PHP and HTML, rather than mechanically emphasize the code completely separate (completely separate. It is extremely stupid idea). The reason why it is mainly for the convenience and transparency of web designers, not entirely, for the program itself - the program itself is enough to do two logical layers, it is enough to solve it through the secondary compilation of the template. This contradictory, and it also implements transaction logic and display logic. Since the template syntax is not complex, it is also simple and strict, so the source program of these classes is not large, only 18.2K, plus some auxiliary functions, no more than 22K, mainly use A powerful regular expression. And they are generally not used when writing a web application, mainly when writing a template compilation environment, because when you use a template in a web program, you only need to simply include the second compilation of the second time inClude. The post-file file is OK. As for the use of Flash PHP, I have done it, using standard XML methods can do anything, the PHP of the background can do not have to have any display output, it outputs the standard XML data, mainly the front desk Flash will return The results are shown.
But this is a big summary, such as Unicode is a problem, although Flash6 supports a lot of Unicode, but it still supports enough, at least three bytes of Unicode, it supports it, and sometimes Not very convenient. In fact, this Flash PHP is actually the data transmitted between the XML format between Server and the Client side, the background processing server-side PHP, the front desk display client's flash, and the oldest C / S application from essentially There is no difference, the only difference is that the high-level protocol used is different. At this time, the PHP itself is the server. That is no problem, but now it is fine. Because I am doing now is a framework, this template compile unit is just a module of the entire framework, and it may not be able to run separately, and my example and web program is also built on this frame. This framework is the architecture I said with the Delphi project. The library and program unit are separated. The directory movement is not any problem. Some pure static media files such as pictures can also be placed on the other. Do not support PHP. on. So far, there is a total of ten modules, with: 1, package compression (TAR and TGZ, direct packaging, add file, delete file, unpack, list, update, add update, etc. Support batch operation, and support wildcards, support subdirectory recursive compression, file name sensitive sensitive can be customized 2, encoding conversion (GB18030, GBK, GB2312, BIG5, UTF8, 16, 32 mutual transfer, Chinese Transfer, Chinese string and substring accurate length, etc .; have an extended specification, convenient to Japanese, Korean, etc., internal coding UCS4. The above conversion may have deviations in Chinese, and the other is exact conversion) Has completed 3, time processing (precise processing world-time zone-time zone is accurate to time zone in Win2K area settings, there are different ways to handle the same time zone but different places; precisely processing around the world Summertime - The calculation error generally does not exceed 2 seconds, all the start-up points of all daylight saving time reference for Win2K time zone settings, such as the Eastern Canada starts in the morning of April at 2:00 every year to October The last day of the first Sunday, etc., etc., but the summary information has not yet entered, too much, just do the interface; there is a calculation zodiac, constellation, etc. - Zodiac is accurate to the Lunar New Year, the constellation is accurate to the sky; All time-related calculations use UNIX timestamps, the output is a conversion timestamp; the calculation output of the zodiac and the constellation is an integer, so there is no localization problem) (last week update: rewrite some of the contents of the time date module, Make timestamps support from the first year to 1999, it makes up for the shortcomings of UNIX timestamps, and increases the date amendment of 1582, and the leap year judgment is also adjusted accordingly. The calculation of the week is also adjusted for 1582 amendments. Can calculate the distance from one day and the first day of the month of the year, the starting point is calculated at 00:00:00 daily, absolutely precise. At the same time, it is compatible with the UNIX timestamp, that is, between 1970 and 2038. The timestamp is consistent with the expansion timestamp. Time zone calculation also uses new functions, but the interface does not change.
New Calculation Compliance with the date of the ISO8601 specification) has been completed 4, permission system (two-dimensional permissions, can define user and user groups, support allowing and denial, can define preset group privileges, customizable specific space strategy, can Dynamically set whether a user can call a certain space in a preset group - overload a few methods, you can know the specific authority of a certain space in a certain space; all parameters are string input, easy to save Store in the database) completed 5, pagination (this is not to say, support on page, next page, home page, last page, on page, next to the next few pages, support directly to the first few pages; each page display The record number is accurate; can be fault tolerant, if the input parameter error can be automatically corrected) has been completed 6, the file lock (two lock-based-system locks, the analog lock, can be specified, but do not support automatic detection, because it is not this class What should be done; support file lock - including shared lock and row lock; in addition to file locking, support page lock-only locks some files, but only support writing, read data can not be locked, this page is locked It can also be changed to a single record lock, the principle is similar) has completed 7, universal database interface (simple, currently supporting mysql, can be expandable, support restriction Query LIMIT - interface universal, only need to overload several methods, But the function is not complicated, not the most complete, there is too much written, and there is no need for me) This section has completed 8, secondary compilation template (support resource file, language package, custom process control) The template is completely separated from the code; the resource file is clearly defined, and it is clear, especially for translation, there is no need to translate the zero-scattered text in the entire HTML file, and only need to translate the entry in the resource file. And these entries support are supported by the format; language pack also supports different single-multiplexed numbers - similar to localization in Java; second compilation mode, compiled from a set of resource files, language packs, and process control files The template file, the template file can be modified by the artwork without program code; after the US is completed, the second compiles are completed, generate the published PHP script file, of course, can be dynamically compiled when using it) 9, cache (not yet begins, still need to re-conceive) to write it again 10, label system (still treated, it has written one, the ideas are good, but the efficiency is low, now preparing to redesign the process; principle: Pinci) The string is compiled into an intermediate code storage, and the correction can also be reversed. There is an intermediate code in the database. When you need to edit, it will reverse it. When you need to display it, you need to display it, and the reversal is faster, as long as you remove the corresponding tag, When it is turning, it is not necessary to turn itself. It is not necessary to analyze it, but it is directly replaced. Only when you write to the database, you need to translate the most original expressions into an intermediate code. This takes a little time and resources. But because the opportunity of general writing is relatively small, it is worth it.