tags:

views:

69

answers:

2

Hello friends,

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...

+7  A: 

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.

sibidiba
Hii sibidiba, thanks for your reply...Here is my exact prob, user submits a form, and while that form processes, I have to send some output to browser to keep server connection alive... so how wud i do that in cakephp for such a case? I see that you have mentioned about it above in your first reply, but i really didn't get it for my case......
tecks
Possible scenario: First of all, you must submit the form via AJAX. During its executes on the server, a session variable containing the state (e.g. %) is updated. When the submission succeeds, it reload/redirects. Second: between submission and its completion, you do a separate AJAX call in regular intervals that quickly returns the current state from the session variable. It can update an element to display the progress. (Session variables are identified by a client side cookie, but the data is server side. It's cheaper then database calls, however it does not support as good consistency.)
sibidiba
Hi, sibidiba, can you please explain me, how wud I make an ajax call, during the execution of another ajax call in cakephp in the above case?
tecks
Basically different running instances of Cake handle parallel AJAX calls. This is PHP specific: requesting a page initiates a complete and independent execution of the complete PHP program. This means things can happen in parallel, you must ensure transaction safety in your implementation logic.
sibidiba
+1  A: 

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.

Leo
Hi leo thank you for your reply...I know the answer might be out of scope of this forum, but if you cud still elaborate a bit in steps, that might help.....anyways, i reaaly appreciate your help...
tecks
Try something like:http://t.wits.sg/2008/06/25/howto-php-and-jquery-upload-progress-bar/I don't understand why you're having keepalive problems.
Leo