Smarty buffer and smarty Buffer

Source: Internet
Author: User
Tags zts

Smarty buffer and smarty Buffer

First, create a file huancun. php In the main folder, and then create a file huancun.html in the template folder.

The content in huancun. php is:

require("../init.inc.php");    require("../DBDA.class.php");;    $db = new DBDA();    $sql="select * from nation ";    $arr=$db->Query($sql);    $smarty->assign("arr",$arr);    $smarty->display("huancun.html");

The content in huancun.html is:

<Table width = "100%" cellpadding = "0" cellspacing = "0" border = "1"> <tr> <td> Code </td> <td> name </ td> <td> operation </td> </tr> <{foreach $ arr as $ v}> <tr> <td> <{$ v [0]}> </td> <{$ v [1]}> </td> <a href = "shanchu. php? Code = <{$ v [0]}> "> Delete </a> <a href =" xiugai. php? Code = <{$ v [0]}> "> modify </a> </td> </tr> <{/foreach}> </table> <a href = "tianjia. php "> Add </a>

On this basis, I want to create a cache file, so I have to modify it in huncun. php, and also perform paging cache processing.

<? Php // defines the number of pages in the current position $ p = 1; if (! Empty ($ _ GET ["page"]) {$ p = $ _ GET ["page"];} // defines the location of a cache page, usually put in the cache file $ filename = ".. /cache/huancunpage?$p=.html "; // defines the cache time. filemname indicates the cache file modification time $ tj = 10; // determine whether the current page needs to be cached if (file_exists ($ filename) & filemtime ($ filename) + $ tj> = time ()) {// If a cache page exists, the cache include ($ filename);} else {// regenerate cache ob_start (); // enable cache require (".. /init. inc. php "); require (".. /DBDA. class. php "); require (".. /page. class. php "); $ db = new DBDA (); $ ztss =" select count (*) from nation "; $ zts = $ db-> StrQuery ($ ztss ); $ page = new Page ($ zts, 5); $ SQL = "select * from nation ". $ page-> limit; // note that the space after nation is required. $ arr = $ db-> Query ($ SQL ); $ smarty-> assign ("page", $ page-> fpage (); $ smarty-> assign ("arr", $ arr ); $ smarty-> display ("huancun.html"); $ str = ob_get_contents (); // obtain the content file_put_contents ($ filename, $ str) from the memory ); // put the obtained content in the cache file ob_flush (); // clear the cache echo "######"; // This is to test whether the cache exists}

 

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.