How to adjust your code
HTML_Progress::display()
When you coded a loop such as:
- <?php
- require_once 'HTML/Progress.php';
-
- $bar = new HTML_Progress();
-
- // ...
-
- do {
- $bar->display();
- if ($bar->getPercentComplete() == 1) {
- $break;
- }
- $bar->incValue();
- } while(1)
- ?>
the sleep action in version 1.1 (an empty for-loop) was included inside
HTML_Progress::display method.
Now in version 1.2 a new API comes: HTML_Progress::sleep
which used in most case the PHP function http://www.php.net/manual/en/function.usleep.php,
rather than an empty for-loop. You should include this new method in your do-while loop,
as in implementation below:
- <?php
- require_once 'HTML/Progress.php';
-
- $bar = new HTML_Progress();
-
- // ...
-
- do {
- $bar->display();
- if ($bar->getPercentComplete() == 1) {
- $break;
- }
- $bar->sleep();
- $bar->incValue();
- } while(1)
- ?>
| Of course, you need the HTML_Progress::sleep method only to produce demonstration. In real
world the user task should at least enough long to delay and smooth progress meter animation. |
HTML_Progress::run()
This new API allows to replace a do-while loop as in above example.
Its also allows to call a user-callback defined by HTML_Progress::setProgressHandler
and manage both progress meter mode (determinate and indeterminate).
HTML_Progress::hasErrors(), HTML_Progress::getError()
These new API allows to catch HTML_Progress internal errors more easily.
See Advanced Error Handling for details.
- <?php
- require_once 'HTML/Progress.php';
-
- $bar = new HTML_Progress();
- $e = $bar->setAnimSpeed(10000); // < - - - will generate an API error
-
- if ($bar->hasErrors()) {
- $err = $bar->getError();
- echo '<h1>Catch HTML_Progress Error</h1>';
- echo '<pre>';
- print_r($err);
- echo '</pre>';
- }
- ?>