我在我的控制器中有這個工作函數。Yii:如何把積極的計時器/經過時間
public function time_elapsed_string($ptime)
{
$etime = time() - $ptime;
if ($etime < 1)
{
return '0 seconds';
}
$a = array(12 * 30 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach ($a as $secs => $str)
{
$d = $etime/$secs;
if ($d >= 1)
{
$r = round($d);
return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago';
}
}
}
,並把它在我的觀點:
$this->time_elapsed_string(strtotime($model->created_on))
輸出是好的,但它如何更新了刷新頁面的某些觀點,與5至10秒的時間間隔?
做一個ajax調用或實現這個計時器在JS –
我希望yii有這樣做很酷和簡單的方法。 –
保存數據庫中的時間戳,並與之相比較! – tinybyte