0%

PHP Smarty引擎 insert用法

Smarty可以开启缓存,下次请求的时候速度就会快很多,但在页面的某些地方,我们可能不需要缓存,比如说显示当前时间,如果用缓存,每次刷新都是第一次请求的时间,不会变。insert功能在于,每次请求时都会重新执行指定的函数,而不会去读取缓存。 模板: {insert name="currentTime"} 上面的代码,会使php在每次请求时执行insert_currentTime()方法,注意,在php中要加前缀insert_ php源代码:

<?php
require_once 'libs/Smarty.class.php';
$smarty=new Smarty();
$smarty->caching=true;
//开启缓存
$smarty->display("a.html");
function insert_currentTime()
{
    return date("Y-m-d H:m:s");
}
?>