ThinkPHP 静态页缓存

通过对ThinkPHP的学习,记录下静态页的缓存步骤,以便以后查阅:

1、配置配置文件/Admin/Conf/config.php代码如下:

/*静态缓存*/
'HTML_CACHE_ON'=>true,
'HTML_PATH'=>'__APP__/html',
'HTML_FILE_SUFFIX'=>'.html',

2、/Admin/Conf/下建立htmls.php(缓存的配置方法查看手册),简单代码如下:

<?php
return array(
    'getHtml'=>array('{:action}',-1),
);
?>

3、/Admin/Lib/Action/IndexAction.class.php添加getHtml操作

public function getHtml(){
    $this->assign('title','页面静态缓存');
    $this->assign('intro','页面静态缓存的内容页面静态缓存的内容页面静态缓存的内容');
    $this->display();
}

4、建立模板文件/Admin/Tpl/default/Index/getHtml.html

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{$title}</title>
</head>
<body>
{$intro}
</body>
</html>

5、访问http://mythink.com/admin.php/Index/getHtml

6、访问http://mythink.com/Admin/Html/getHtml.html

If the copyright belongs to the longfei, please indicate the source!!!
原文地址:https://www.cnblogs.com/longfeiPHP/p/4977828.html