开发者

cakephp: send output to browser while executing a process/function

开发者 https://www.devze.com 2023-01-04 14:25 出处:网络
How can i make a progress bar in cakephp? and other related question is,开发者_运维知识库 lets say, for a loop, how can I send output to the browser for every iteration..... in cakephp....

How can i make a progress bar in cakephp?

and other related question is,开发者_运维知识库

lets say, for a loop, how can I send output to the browser for every iteration..... in cakephp.... I tried using setflash function, but didnt worked for me....

My main intention in trying above things, is that I want to send some output to browser for every few seconds while my function is getting executed, else I go into the problem of timout.....

Thanks...


You can't really do that. A returned web page is something static, you can't change it when you sent it. In pure PHP you could send portions of the output before you have all the output, so you can have something like for($i=0;;) echo $i++; but you can't do this in Cake because you need to render a View completely before inserting it into the layout. A progress bar is in (pure) HTML impossible, because as said, you can't modify a sent HTML response.

However, you can bring JavaScript into play: You can return a HTML page with the JS, that uses AJAX calls to query the state/percentage of an action, and then it sets the progress bar in the HTML respectively. It can do the latter (modify HTML) because JS runs in the clients' browser after page retrieval.


You can't do that using PHP (or CakePHP) on its own. You can do it using AJAX and PHP (or CakePHP) but to explain that would be beyond the scope of this forum. Google "AJAX PHP progress" and take the time to learn how to do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号