This article mainly introduced the thinkphp realization site static method, Thinkphp provides an effective method to generate static pages, with a certain reference value, interested in small partners can refer to.
Thinkphp provides a valid way to generate static pages, as explained in the Manual of Tp2.0, 3.0 of which are not described in the 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, the static file setting A/index. Then the saved path is the project path/html/a/index.html (the default static path is not created on the project path under the Html folder)
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 ');
Such three formats are equivalent
The following is a static implementation, with two methods
Can be added under the current module, such as the above statement, so long as the running of the module will produce the specified directory of "module. html" file, the usual practice is that the site after the construction, specifically write a method, and then let it execute, so that the entire site to generate 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 project must be emptied