#1 zhgzzy
找了一个时间显示的函数,请问一下这个要放在哪里???
function time_tran($the_time){
$now_time = date("Y-m-d H:i:s",time()+8*60*60);
$now_time = strtotime($now_time);
$show_time = strtotime($the_time);
$dur = $now_time - $show_time;
if($dur < 0){
return $the_time;
}else{
if($dur < 60){
return $dur.'秒前';
}else{
if($dur < 3600){
return floor($dur/60).'分钟前';
}else{
if($dur < 86400){
return floor($dur/3600).'小时前';
}else{
if($dur < 259200){//3天内
return floor($dur/86400).'天前';
}else{
return $the_time;
}
}
}
}
}
}
2010-05-18 11:30:41
#4 zhgzzy
<{time_tran($one.intime)}> 怎么不显示
2010-05-18 11:52:44
#5 jake
在smarty中显示要通过spAddFunction这个函数将函数注册到模板中。
具体请看smarty手册中关于注册函数到模板的说明。
2010-05-18 11:55:18
#6 zhgzzy
是不是在这个函数文件中加下面一行???
spAddViewFunction('time_tran', array(& $this, '__smarty_time_tran'));
2010-05-18 14:14:18
#7 jake
如果是sp3,就是放到入口文件 require(speedphp.php) 和 spRun 之间。
sp2的话,直接放到控制器的文件开头
2010-05-18 14:33:10
#10 bobo183
回复 9 jake 就是格式化时间
读取数据库里存储的时间,然后格式化成 “几秒钟前”,“几分钟前”等这种格式的!
函数已经写好了,但是要怎么在模版里输出了?
2011-04-14 18:08:50
#11 ltotal
在入口文件include一个公用函数调用文件,把一楼的函数放进去,然后在模板直接写<{time_tran($the_time)}>或者<{$the_time|time_tran}>,又或者做成modifier插件也成啊,SP可以在‘view’ => 'config' => 'plugins_dir' 以数组形式配置多个可能存在的Smarty插件目录。
2011-04-14 19:40:45