Home  >  Article  >  Backend Development  >  Detailed explanation of Thinkphp’s method of implementing static site

Detailed explanation of Thinkphp’s method of implementing static site

黄舟
黄舟Original
2017-03-22 09:19:362376browse

This article mainly introduces Thinkphp's method of achieving static site. Thinkphp provides an effective method of generating static pages, which has certain reference value. Interested friends can refer to it.

thinkphp provides an effective method of generating static pages (it is explained in the tp2.0 manual, but not in the 3.0 manual, but the 3.0 method still exists.)

$this->buildHtml('静态文件', '静态路径','模板文件');

Let me explain the parameters a little bit. Some friends asked me about this parameter and how to use it.

Parameter 1: Static file refers to the generated static file name. The complete file saving path is: static path/static file. For example, the static file is set to a/index. Then the saved path is the project path/Html/a/index.html (the default static path is in the Html folder of the project path, and you can create it yourself)

Parameter 2: Static path, the default path has been explained above. In 3.0, you can add parameters to the entry file to change the static path.

define('HTML_PATH', './'); (define the static path as the website root directory)

Parameter three: Template file, I feel that the official description is incorrect. To be precise, it should be the target module, which is the module that needs to generate static files. Format: module name: operation. For example, if you want to generate the a method under Index as a static file, that is Index:a. If empty, the static file of the current operation will be 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");

These three formats are equivalent

The following is the static implementation, just two methods

You can add the above statement under the current module, then as long as the module is run, the "module.html" file in the specified directory will be generated. The usual method is to write a special method after the site is built, Then let it execute to generate static files for the entire site at once. Note: If the site is edited or adjusted, the cache must be cleared once, that is, the Runtime folder under the project must be cleared

The above is the detailed content of Detailed explanation of Thinkphp’s method of implementing static site. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn