PHPSmarty页面静态化加分页和缓存控制
PHP页面
创新互联主营六安网站建设的网络公司,主营网站建设方案,成都App定制开发,六安h5微信小程序定制开发搭建,六安网站营销推广欢迎六安等地区企业咨询
left_delimiter="<{"; $smarty->right_delimiter="}>"; //设置为false 定界符号左右可以有空格 $smarty->auto_literal = false; //添加一个插件的目录 //$smarty->setPluginsDir(ROOT."/libs/myplugins/"); //注意添加一个插件,要把系统默认设置的路径加入 否则不能使用默认系统的插件 $smarty->setPluginsDir(array( ROOT."/libs/plugins/",//系统默认设置的路径 ROOT."/libs/myplugins/",//自定义的 )); //连接数据库 try{ $pdo = new PDO(DSN, DBUSER,DBPWD); }catch(PDOException $e){ echo "数据库连接失败:".$e->getMessage(); exit; } $query = "select id, username, password,email from users limit 3"; $stmt = $pdo->prepare($query); $stmt ->execute(); $users = $stmt->fetchAll(PDO::FETCH_ASSOC); $smarty->assign('users',$users); //var_dump($users); $query = "desc users"; $stmt = $pdo->prepare($query); $stmt ->execute(); $tdname = $stmt->fetchAll(PDO::FETCH_COLUMN); //var_dump($tdname); $page = new Page(20, 2); $smarty->assign('tdname',$tdname); $smarty->assign('fpage',$page->fpage()); //变量输出 $smarty->display('hello.tpl'); //返回输出缓冲区的内容 $content = ob_get_contents(); //将一个字符串写入文件 file_put_contents("./cache/newindex{$_GET['page']}.html", $content); //冲刷出(送出)输出缓冲区中的内容 ob_flush(); echo "缓存文件不存在,查询数据库,再生成缓存文件,输出到浏览器"; }else{ include $file; echo "直接加载缓存文件"; } ?>
模板tpl页面
<{config_load file="../config/my.conf " section="index"}> '><{#title#}>
index | iteration | <{foreach $tdname as $val}><{$val}> | <{/foreach}> <{section name="one" loop=$users }> <{if $smarty.section.one.first}>|||
---|---|---|---|---|---|
<{$smarty.section.one.index}> | <{$smarty.section.one.iteration}> | <{$users[one].id}> | <{$users[one].username}> | <{$users[one].password}> | <{$users[one].email}> |
<{$fpage}> |
浏览器页面
当前题目:PHPSmarty页面静态化加分页和缓存控制
本文路径:http://pwwzsj.com/article/pjpoeo.html