目前,我在 MVC-Zend-Framework 3 应用程序中使用进度栏时遇到问题。 我完全按照 Zend-documentation 中给出的说明进行操作。 .
但我的问题是,我看到一个空的进度条,它没有更新,而我的长时间运行的 php 脚本正在工作(没有文件上传,但计算作业大约需要几分钟)。看来,进度条的更新函数没有被调用......
一些片段:
a) index.phtml 文件 (备注:与文档相比,我更改了 iframe 的位置和大小,以检查长时间运行的 php 脚本的调试输出)
$this->headTitle('Test-Page');
$this->h1('Test-Page');
?>
<style>
#long-running-process {
position: absolute;
left: 100px;
top: 100px;
width: 500px;
height: 500px;
}
#zend-progressbar-container {
width: 100px;
height: 30px;
border: 1px solid #000000;
background-color: #ffffff;
}
#zend-progressbar-done {
width: 0px;
height: 30px;
background-color: #000000;
}
</style>
<script type="text/javascript">
function Zend\ProgressBar\Update(data)
{
document.getElementById('zend-progressbar-done').style.width = data.percent + '%';
}
</script>
<div>
This page demomstrates the use of the Zend Progressbar:
</div>
<div id="zend-progressbar-container">
<div id="zend-progressbar-done"></div>
</div>
<iframe src="long-running-process.php" id="long-running-process"></iframe>
b) 长时间运行的 php 脚本的一部分:
$this->adapter = new Adapter\JsPush();
$this->progressBar = new ProgressBar($this->adapter,0,100);
//[...]
// in a long running while-loop is this code:
$this->progressBar->update(round($progress));
//end in the end:
$this->progressBar->finish();
如上所述,进度条没有改变,但保持为零值。不幸的是我无法在互联网上找到任何可行的示例。
此外,我不仅有兴趣“推送”该值,还可能将一些状态消息“推送”到进度条(如文档中提到的那样),但相应的语法对我来说并不清楚。
感谢您提前提供的任何帮助!
最佳答案
好吧,与此同时,我可以自己回答这个问题:-)
description JsPush-adapter 的声明中, update-method 的默认值为
Zend\ProgressBar\Update
正如我的问题所示,脚本中的方法正是这个名称。当我将该方法重命名为类似
function ZendProgressBarUpdate(data)
并在适配器初始化后添加以下行:
$this->adapter->setUpdateMethodName("ZendProgressBarUpdate");
一切都按预期进行。
关于javascript - Zend框架3 : How to use and (push-)UPDATE progressbar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50396543/