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}