Home > PHP Framework > ThinkPHP > body text

How thinkphp5 generates static html files

爱喝马黛茶的安东尼
Release: 2019-08-23 10:28:31
Original
7579 people have browsed it

How thinkphp5 generates static html files

thinkphp itself comes with an effective method of generating static pages (this method is explained in the tp2.0 manual, but not in the 3.0 manual, but the 3.0 method It still exists.)

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

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, there is no one that can be created by yourself)

parameters Two: Static path, the default path has been explained above. In 3.0, parameters can be added to the entry file to change the static path.

Related recommendations: "ThinkPHP Tutorial"

define('HTML_PATH', './');(将静态路径定义为网站根目录)
Copy after login

Parameter three: Template file, I feel that the official description is incorrect, to be precise it should be the target Module 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:

The code is as follows:

class IndexAction extends Action {
    public function index(){
    $this->buildHtml("index",'',"");
    $this -> display();
    }
}
Copy after login

In fact, the

code is as follows:

$this->buildHtml("index",'',"");
Copy after login

The code is as follows:

$this->buildHtml("index",'',"Index:index");
Copy after login

The code is as follows:

$this->buildHtml("index",'',"index");
Copy after login

The three formats are equivalent. You can add statements under the current module. Then as long as the module is run, the "module.html" file in the specified directory will be generated. Usually The method is to write a special method after the site is built, and then let it be executed so that the entire site can generate static files 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 How thinkphp5 generates static html files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template