Use thinkphp's own method to generate static html files

不言
Release: 2023-03-30 08:32:02
Original
4286 people have browsed it

This article mainly introduces the use of thinkphp's own method to generate static html files. It has certain reference value. Now I share it with you. Friends in need can refer to it.

thinkphp itself comes with a An effective method to generate static pages. This article mainly introduces the use of thinkphp's own method to generate static html files

thinkphp itself comes with an effective method to generate static pages (this method is in tp2.0 There are instructions in the manual, but there are no instructions in the 3.0 manual, but the 3.0 method still exists.)

$this->buildHtml('static file', 'static path','template File');

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, you can create it yourself)

Parameter 2: 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. 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:

Copy code The code is as follows:

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

Actually


Copy code The code is as follows:

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

Copy code The code is as follows:

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

Copy code The code is as follows:

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

Three formats like this It is equivalent

You can add statements under the current module, then as long as you run the module, 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, and then Let it execute so that the entire site will 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.                            

Related recommendations:

ThinkPHP file upload example



##

The above is the detailed content of Use thinkphp's own method to generate 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!