Generate static html file details using thinkphp native method

  • 2021-06-29 10:41:00
  • OfStack

thinkphp itself comes with an effective method for generating static pages. (This method is described in the tp2.0 manual, not in the 3.0 manual, but the 3.0 method still exists.)

$this- > buildHtml ('Static File','Static Path','Template File');

With a little explanation of the parameter, some friends asked me how to use it.

Parameter 1: Static file refers to the static file name after the generation. The file save path is complete: static path/static file.For example, a static file setting a/index. The path to save is the item
Target Path/Html/a/index.html (The default static path is under the Html folder of the project path, which you cannot create yourself)

Parameter 2: Static path, the default path has been explained above, and 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 site root directory)

Parameter 3: Template file, I feel that the official description is incorrect, it should be the target module, that is, the module that needs to generate static files.Format: Module name: Operation.For example, the a method under Index is a static file, which is Index:a.If empty, a static file for the current operation is generated by default.
Example:

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

actually
$this->buildHtml("index",'',"") ; 
$this->buildHtml("index",'',"Index:index") ; 
$this->buildHtml("index",'',"index");

These three formats are equivalent

Statements can be added to the current module so that any running of the module will result in a "module.html" file in the specified directory. The usual practice is to write a method after the site has been built and let it execute so that the entire site can generate static files once. Note: If the site has edits or adjustments, the cache must be cleared once.The Runtime folder under the project must be emptied.

More readers interested in thinkPHP-related content can view this site's topics: Introduction to ThinkPHP, Summary of thinkPHP Template Operating Skills, Summary of ThinkPHP Common Methods, Introduction to smarty Template, and Technical Summary of PHP Template.

I hope that the description in this paper will be helpful to everyone's PHP program design based on the ThinkPHP framework.


Related articles: