PHP tips: Explain the phplib template application process and running principle

Source: Internet
Author: User
For more information, see "htmlheadbody! -- BEGINRowSort -- {SortList} br! -- ENDRowSort --/body/head/htmlindex. php content :? $ T-set_file (Index, inde

Detailed description of phplib template application process and running principle

Index.htm file content:





{SortList}




Index. php content:

$ T-> set_file ('index', 'index.htm ');
$ T-> set_block ('index', 'rowsort ', 'rowssort ');
........................................ ......
... $ List_sort ...................
$ T-> set_var ('sortlist', $ list_sort );
$ T-> parse ('rowssort ', 'rowsort', true );
........................................ ......
........................................ ......
$ T-> parse ('out', 'index ');
$ T-> p ('out ');
?>

Specific analysis process:

1. $ t-> set_file ('index', 'index.htm'); $ this-> file [Index] = index.htm


2. $ t-> set_block ('index', 'rowsort ', 'rowssort ');

1. load the index.htm content of the indexfile and assign it to the variable $ this-> varvals [index]
2. $ str = $ this-> varvals [index] get template file content
3. use the preg_match_all function to match the content in the corresponding block (RowSort) in the template file and store it in $ m [1] [0 ].
4. Why 0? Switch the content (including the header and tail) in the Φ Phi shortlock (RowSort) to {RowSort}
5. variable $ this-> varvals [RowSort] = $ m [1] [0], $ this-> varkeys [RowSort] =/{RowSort }/
6. variable $ this-> varvals [index] = $ str (the content has changed. see Step 2), $ this-> varkeys [index] =/{index }/


III. $ t-> set_var ('sortlist', $ list_sort );

Set $ this-> varvals [SortList] = $ list_sort
Set $ this-> varkeys [SortList] =/{SortList }/


4. $ t-> parse ('rowssort ', 'rowsort', true); (this control is repeated based on the sort size)

1. use the subst function to process all the variable values in the $ this-> varvals array against the special characters \ and $ that may be contained in the variable values (\ and $ to distinguish between \ and \ $, this ensures that the next step of preg_replace does not appear unexpectedly), and assigns it to the $ varvals_quoted array.
2. $ str = $ this-> varvals [RowSort]
3. we can see that $ str contains a {SortList}, which is composed of three: $ this-> varkeys [SortList] =/{SortList }/, $ this-> varvals [SortList] = $ list_sort
4. after preg_replace, we can see that $ str is the content after the PHP template variable {SortList} has been parsed, and $ str is returned.
5. assign a continuation value to $ this-> varvals [RowSort] // There is a title here. you may consider that the {RowSort} at the beginning of the display is not parsed, so don't worry, phplib has the finish function to process it based on your request.


5. $ t-> parse ('out', 'index ');

1. as you can see, $ this-> varvals [index] has a PHP template variable to be parsed, that is, {RowSort}
2. in the previous steps, we have resolved the content of $ this-> varvals [RowSort ].
3. in this way, all the PHP template variables have been parsed and assigned to the variable $ this-> varvals [OUT].

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.