Smarty method of implementing page static (HTML generation), Smarty static _php tutorial

Source: Internet
Author: User

Smarty method of implementing page static (HTML generation), Smarty static


The example in this article describes how Smarty implements the static page (HTML generation). Share to everyone for your reference, as follows:

In order to reduce the number of database reads, some of the content is not often changed pages, such as the article detail page needs to be made into HTML static pages.

In the case of using smarty, you can also implement page statics. Let's start with a brief look at the usual dynamic reading when using Smarty.

These steps are generally divided into:

1. Pass a parameter (ID) via URL;

2, then query the database based on this ID;

3, after obtaining the data, modify the display content as needed;

4, assign need to display the data;

5. Display template file.

The Smarty static process requires only two steps to be added in the above procedure:

First: Use Ob_start () to open the buffer before 1.

Second: After 5, use Ob_get_contents () to get the contents of the memory not output, and then use Fwrite () to write the content to the destination HTML file.

As described above, this process is implemented in the foreground of the website, and content management (add, modify, delete) is usually done in the background in order to effectively

Using the above procedure, you can use a small method, that is, the header (). The process is as follows: After adding and modifying a program, use the

Header () (and, of course, other ways) jumps to the foreground to read, which enables the HTML of the page, and then jumps back to the admin side after the HTML is generated, and these two jumps

The process is not visible.

<?php$cachefile= "./cache/demo.html";//put the cache file in a folder $cachetime=20;if (!file_exists ($cachefile) | | Filemtime ($cachefile) + $cachetime < Time ())//determine presence and expiration {  ob_start ();//Output Control  echo '
 
  
  
   
   
  ';  Echo '
  
   
   ';  Echo '
  
   
   
      '; echo " 
     "; echo " 
     "; Echo ' 
    '; Echo ' 
    
      '; echo " 
     "; echo " 
     "; Echo ' 
    '; Echo ' 
   

User

1111122222
1111122222
'; $html =ob_get_contents (); File_put_contents ($cachefile, $html);//output to cache file Ob_end_flush ();//output and close buffer}else{ Echo ' Ceshi '; Include $cachefile;}? >

More interested in smarty related content readers can view the topic: "Smarty Template Primer Basic Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", " PHP Basic Grammar Introductory tutorial, PHP Object-oriented Programming primer, PHP string usage Summary, PHP+MYSQL database Operations Primer and PHP Common database operations Tips Summary

It is hoped that this article will be helpful to everyone based on smarty template PHP program design.

http://www.bkjia.com/PHPjc/1133094.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133094.html techarticle Smarty Implement the method of page static (generate HTML), Smarty static This article describes the method smarty implement the page static (generate HTML). Share to everyone for your reference, as follows: ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.