ThinkPHP provides an efficient way to generate static pages (described in the tp2.0 manual, not in the 3.0 manual, but the 3.0 method does exist).

$this->buildHtml($this->buildHtml);

Some friends asked me about this parameter and how to use it.

A parameter:Static file refers to the generated static file name, the file save path is complete: static path/static file. For example, static files set a/index. Then the save path is the item

Path /Html/a/index.html(the default static path is in the Html folder of the project path, you can’t create it yourself)

Parameters of the two:Static paths, the default path described above, can be changed in 3.0 by adding parameters to the entry file.

define(‘HTML_PATH’, ‘./’); (Static path as site root)

Three parameters:Template file, I feel the official description is incorrect, accurately should be the target module, is the module that needs to generate static file, format: module name: operation, for example, to generate Index under the method of A static file, that is Index:a, if empty, the default generation of the current operation of the static file.

Example code is as follows:

  • class IndexAction extends Action {
  • public function index(){
  • $this->buildHtml(“index”,”,””);
  • $this -> display();
  • }
  • }

Actually,

$this – > buildHtml (” index “, “, “”);

$this – > buildHtml (” index “, “, “index, the index”);

$this->buildHtml(“index”,”,”index”);

So the three formats are equivalent, and here’s the static implementation, just two ways


You can add such statements under the current module, so as long as running the module will produce the specified directory under the “module.html” file, the usual way is to site construction, write a method, and then let it execute, so that the whole site one-time generation of static files,
Note:If there are edits or changes to the site then the cache must be cleared once, that is, the Runtime folder under the project must be cleared.