Some basic syntaxes and functions in phplib _ MySQL

Source: Internet
Author: User
Some basic syntaxes and functions in phplib, bitsCN.com

Syntax introduction:
Common methods in phplib include set_file, set_block, set_var, parse, ppasre, p, and get.
Statement: because the system uses phplib, if there is a braces on the page, this will be replaced with a blank space, so when writing this article, use "[[", "]" to replace braces. When we use it, we use braces to make it easier to write articles.
Set_file: used to introduce the template file.
Usage:

$ T-> set_file ("show_main", "main.htm ");
Or
$ T-> set_file (array (
"Show_header" => "header.htm ",
"Show_main" => "main.htm"
));

Set_block: used to declare a block
Usage:
$ T-> set_block ("show_main", "rowlist", "RL ");
Show_main is the file handle obtained using set_file, and rowlist is the region ID on the template page.
  

  
  







                 
[[Param]


As shown aboveAs a block, you can use a loop to generate a list of multiple rows.
Blocks can be nested.
  

  
  







                       
[[Param]


As shown above, this declares a nested block, which is used in the image volume of boeiBlog. if you are interested, you can find it.
For nested templates, we can use
$ T-> set_block ("show_main", "rowlist", "RL"); // The parameters in the table are contained from the beginning to the end, and the last one is an alias, mainly used for block recognition
$ T-> set_block ("rowlist", "collist", "CL"); // The first parameter is the name of the external block, and the second parameter is your own name, the third is the alias.
Pay special attention to loop through such blocks.
As follows:
  

  
$ T-> set_block ("show_main", "rowlist", "RL ");
$ T-> set_block ("rowlist", "collist", "CL ");
For ($ I = 0; $ I <5; $ I ++)
{
$ T-> set ("CL"); // Here we need to clear the appended column loop once, otherwise there will be a bunch of more things
For ($ ii = 0; $ ii <5; $ ii ++)
{
$ T-> set_var ("param", "boeiBlog ");
$ T-> parse ("CL", "collist", true); // the true parameter indicates that this is an append.
}
$ T-> parse ("RL", "rowlist", true); // true here is also table appending.
}

The code above will generate a 5x5 table, and a boeiBlog will appear in each cell.
Set_var: used to replace variables
In the above code, $ t-> set_var ("param", "boeiBlog") is to replace the param variable in the template with the boeiBlog string. of course, you can also replace it with a variable, such:
  

  
$ Curdate = date ("Y-m-d ");
$ T-> set_var ("param", $ curdate );
Set_var also has append attributes, such:
  

  
$ Curdate = date ("Y-m-d ");
For ($ I = 0; $ I <10; $ I ++)
{
$ T-> set_var ("param ","
". $ Curdate, true );
}

This will generate ten consecutive current dates
Sometimes the append attribute of set_var can be used to replace the block loop.
Set_var can use arrays, such:
  

  
$ T-> set_var (array (
"Param" => "boeiBlog ",
"Title" => "Bai Ai network"
));

The template is as follows:
  

  
  



           
[[Param], [[title]


Parse: used to parse files
After processing all the variables in the template, you can use parse to parse the template. This is the last process of template processing.
For example:
  

  
$ T-> set_file ("show_index", "index.htm ");
$ T-> set_file ("show_main", "main.htm ");
$ T-> set_var ("param", "boeiBlog ");
$ T-> parse ("main", "show_main ");

The template we use may be:
  

  
Main.htm
  



           
[[Param]


If there is another template, its structure is as follows:
  
  
Index.htm
  

[[Main]


In this case, the code will replace the variables in main.htmwith boeiblogand then put them to the main in index.htm. finally,

Table in tag
After the resolution is complete, the output page is displayed,
P: Used to output pages
For example:
  

  
$ T-> set_file ("show_index", "index.htm ");
$ T-> set_file ("show_main", "main.htm ");
$ T-> set_var ("param", "boeiBlog ");
$ T-> parse ("main", "show_main ");
$ T-> parse ("index", "show_index ");
$ T-> p ("index"); // The entire indexpage is output, and main.htmis inserted into index.htm, so $ t-> p ("main") is not required ");

Pparse: same as p, it is also used to output pages.
For example:
  

  
The above code can be simplified as follows:
$ T-> set_file ("show_index", "index.htm ");
$ T-> set_file ("show_main", "main.htm ");
$ T-> set_var ("param", "boeiBlog ");
$ T-> parse ("main", "show_main ");
$ T-> pparse ("index", "show_index"); // combine p and parse to complete parsing and output immediately.

Get: get file content
For example:
  

  
$ T-> set_file ("show_index", "index.htm ");
$ T-> set_file ("show_main", "main.htm ");
$ T-> set_var ("param", "boeiBlog ");
$ T-> parse ("main", "show_main ");
$ T-> parse ("index", "show_index ");
$ Getstr = $ t-> get ("index ");
Echo $ getstr; // you will see that this is actually the same as p.

With get, we can easily obtain the content of the generated page, which can be used for static page generation. We can see that phplib is very convenient for processing static pages.

BitsCN.com

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.