Home > Backend Development > PHP Tutorial > How to generate static web pages through smarty_PHP tutorial

How to generate static web pages through smarty_PHP tutorial

WBOY
Release: 2016-07-13 17:49:49
Original
904 people have browsed it

The biggest function of Smarty is to cache template pages. That is to say, two steps can be completed through Smarty: compilation + analysis
Step one: compile. It means to replace the tag of the template file with pure PHP, and then save it in the cache location. The saved file extension is PHP. I call this step compilation (this is my own name, not official)
Step two: analysis. That is to say, it just parses and executes the PHP file you just compiled~~ No need to explain this
Let’s get to the point and add the following code to the Smarty.class.php file
function MakeHtmlFile($file_name, $content)
{                 //Create the directory if it does not exist
If (!file_exists (dirname($file_name))) {
If (!@mkdir (dirname($file_name), 0777)) {
die($file_name."Directory creation failed!");
              }
          }
                                                                            If(!$fp = fopen($file_name, "w")){
echo "File opening failed!";
                  return false;
          }
If(!fwrite($fp, $content)){
echo "File writing failed!";
                    fclose($fp);
                  return false;
          }
                                                               fclose($fp);
chmod($file_name,0666);
}
The function of this function is to save the file~~
The calling method is as follows
require '../libs/Smarty.class.php';
$smarty = new Smarty;
//…………Omit variable definition and assignment
//$smarty->display('index.tpl');
$content=$smarty->fetch("index.tpl");
$smarty->MakeHtmlFile('./index.html',$content);//Generate

Excerpted from PainsOnline’s column

http://www.bkjia.com/PHPjc/478329.html

truehttp: //www.bkjia.com/PHPjc/478329.htmlTechArticleSmarty’s biggest function is to cache template pages. That is to say, two steps can be completed through Smarty: compilation + analysis. The first step: compilation. It means replacing the tags of the template file with pure php, and then...
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