Using thinkphp to generate static HTML files

Source: Internet
Author: User
Thinkphp itself has a valid method of generating a static page, which is illustrated in the Manual of Tp2.0, which is not stated in the 3.0 manual, but the 3.0 method still exists. )

$this->buildhtml (' Static file ', ' Static path ', ' template file ');

A little explanation of the parameters, some friends asked me this parameter and how to use.

Parameter one: Static files, refers to the generated static file name, the file save path complete is: Static path/static file. For example, static file Settings A/index. Then the saved path is the item
Target path/html/a/index.html (default static path under the Html folder of the project path, no can be created by itself)

Parameter two: Static path, the above has explained the default path, 3.0 can add parameters in the Portal file to change the static path.
Define (' Html_path ', './'); (the static path is defined as the Web site root directory)

Parameter three: template file, I feel the official description is not correct, it should be the target module, is the module that needs to generate static files. Format: module name: operation. For example, to generate index under the A method is a static file, that is index:a. If empty, the static file for the current operation is generated by default.
Example:

   Class Indexaction extends Action {public      function index () {      $this->buildhtml ("index", "'," ");      $this, display ();      }    }

In fact

$this->buildhtml ("index", "," ");
$this->buildhtml ("index", "'," Index:index ");
$this->buildhtml ("index", "'," index ");

In this way three formats are equivalent

You can add a statement under the current module, so as long as the module is running, it will produce a "module. html" file in the specified directory, and the usual practice is to write a method after the site is built, and then let it execute so that the entire site generates static files at once. Note: If the site has edits or adjustments then you must clean the cache once, that is, the runtime folder under the item must be emptied.


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.