ThinkPHP generates static files

Source: Internet
Author: User
Thinkphp provides an effective method to generate static pages (as described in the tp2.0 manual, not described in the 3.0 manual, but the 3.0 method still exists .) $ This-& gt; buildHtml (...

Thinkphp provides an effective method to generate static pages (as described in the tp2.0 manual, not described in the 3.0 manual, but the 3.0 method still exists .)

$ This-> buildHtml ('static file', 'static path', 'Template file ');

Some friends asked me how to use this parameter.

Parameter 1:A static file is the generated static file name. The Complete file storage path is: static path/static file. For example, if a/index is set for a static file, the saved path is an item.

Path/Html/a/index.html (the default static path is under the Html folder of the project path, and cannot be created by yourself)

Parameter 2:Static path. the default path is described above. in 3.0, you can add parameters to the entry file to change the static path.

Define ('HTML _ path', './'); (the static PATH is the root directory of the website)

Parameter 3:Template File. I think the official description is incorrect. for accuracy, it should be the target module, that is, the module for generating static files. Format: module name: Operation, for example, if the method a under the Index is to be generated is a static file, that is, Index: a. If it is null, the static file for the current operation is generated by default.

The sample code is as follows:

  1. Class IndexAction extends Action {
  2. Public function index (){
  3. $ This-> buildHtml ("index ",'',"");
  4. $ This-> display ();
  5. }
  6. }

Actually

$ This-> buildHtml ("index ",'',"");

$ This-> buildHtml ("index", ''," Index: index ");

$ This-> buildHtml ("index", ''," index ");

In this way, the three formats are equivalent. The following is the static implementation. There are two methods:

You can add a statement like a statement under the current module. if you run this module, the "cmd.html" file under the specified directory will be generated. the common practice is to write a method after the site is built, then let it execute and make the whole site generate static files at a time,Note:If the site has been edited or adjusted, the cache must be cleared once, that is, the Runtime folder under the project must be cleared.

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.