【发布时间】:2015-06-03 03:56:04
【问题描述】:
我正在使用 jquery 倒数计时器,但问题是计时器从每次刷新页面时设置的值开始。我想在第一次获得时间并保存在 PHP 会话中,并从第一次时间和更新会话中减去第二次。在简单的 Word 中,我想创建 php 倒数计时器,使用 php 仅运行 50
这是我的控制器代码
public function actionViewtimer($id) {
$session = Yii::app()->session;
$this->layout = 'countdownlayout';
if (empty($session['countdowntime'])) {
$orderTime = microtime(true); #when user first time enter timer start from 50 mins
$session->add('countdowntime', array($orderTime)); //replace this line
} else {
$time_end = microtime(true);
$orderTime = $time_end - $time_start;
unset($session['countdowntime']);//unset old session
$session->add('countdowntime', array($orderTime)); //when user enter second
}
$getMinutes = $getMinutes_from_orderTime ; #please tell me how we extact minutes and pass them to view
$session->add('timersession', array($rand));
$this->render('viewtimerpage', array(
'getMinutes' => $getMinutes
));
}
这是我的 jquery 代码
<script>
$(function() {
$('#xlarge').countdowntimer({
minutes: 50<?php echo $getMinutes; ?>,
size: "lg",
timeUp: timeisUp
});
});
function timeisUp() {
alert('Time Complete');
return false;
}
</script>
【问题讨论】:
-
我不确定您的问题是什么。你能更好地解释什么应该开始,什么应该停止计时器吗?
-
我不确定您真正尝试做什么,正如@HenriqueBarcelos 所说。但是闪存数据可能会对您有所帮助:yiiframework.com/doc-2.0/…
-
是的,我正在使用 HenriqueBarcelos,当我登陆计时器页面时,计时器从 50 秒开始,假设我在 15 秒后关闭浏览器并再次打开计时器页面,它从 35 秒开始 50-15= 35
-
我认为他正在尝试拥有一个持久的倒计时。