我在 smarty 安装上启用了缓存并具有以下模板功能
function smarty_updatedhour($params, $smarty)
{
$date1 = new DateTime($params['timestamp']);
$date2 = new DateTime("now");
$interval = $date1->diff($date2);
$smarty->assign("updated_period", $interval->format('%h'), true);
}
我已将插件注册为:
$smarty->registerPlugin('function', 'updated_hour', 'smarty_updatedhour', false, array('timestamp'));
我试图测试它是否有效
{updated_hour timestamp=$timestamp_vale}
{$updated_period}
{if $updated_period > 10}
// do other stuffs
{/if}
但它不起作用,但是当我禁用 smarty 页面缓存时,它起作用了。
谁能告诉我是什么问题?