HTML_Progress
[ class tree: HTML_Progress ] [ index: HTML_Progress ] [ all elements ]
Prev Next

Beginner Guide

learn how to use HTML_Progress, basic features

by by Laurent Laville
mailto:pear@laurent-laville.org
November 2003, Laurent Laville
(HTML_Progress 1.0+)

Table of Contents

HTML_Progress Basics

Starting out from scratch

In a hurry you've seen that such code below is not enough to run properly a Progress Bar.

  1. <?php
  2. require_once ('HTML/Progress.php');
  3.  
  4. $bar = new HTML_Progress();
  5.  
  6. echo $bar->toHtml()
  7. ?>

You got only :

Why ? what's wrong with previous code ? It's very simple, HTML_Progress needs some CSS class-selector to work fine. So if you send to browser the necessary styles, all will be ok.

  1. <?php
  2. require_once ('HTML/Progress.php');
  3.  
  4. $bar = new HTML_Progress();
  5. ?>
  6. <style type="text/css">
  7. <!--
  8. <?php echo $bar->getStyle()?>
  9. // -->
  10. </style>
  11.  
  12. <?php
  13. echo $bar->toHtml()
  14. ?>

And the result will be :


Running HTML_Progress

Now you know how to show a basic progress bar, what should we do to run it ?

Let's begin by a simple empty loop. Your code should be something like that :

  1. <?php
  2. require_once ('HTML/Progress.php');
  3.  
  4. $bar = new HTML_Progress();
  5. ?>
  6. <style type="text/css">
  7. <!--
  8. <?php echo $bar->getStyle()?>
  9. // -->
  10. </style>
  11.  
  12. <?php
  13. echo $bar->toHtml()
  14.  
  15. do {
  16.     $bar->display();
  17.     if ($bar->getPercentComplete(== 1{
  18.         break;   // the progress bar has reached 100%
  19.     }
  20.     $bar->incValue();
  21. while(1);
  22. ?>

What's wrong out there ? The progress bar is running but nothing change on browser screen. As for previous error, HTML_Progress needs some CSS class-selector, and also some JavaScript code to work fine. Adds few more lines, and example will be at end :

  1. <?php
  2. require_once ('HTML/Progress.php');
  3.  
  4. $bar = new HTML_Progress();
  5. $bar->setAnimSpeed(100);
  6.  
  7. $ui =$bar->getUI();
  8. ?>
  9. <style type="text/css">
  10. <!--
  11. <?php echo $bar->getStyle()?>
  12. // -->
  13. </style>
  14. <script type="text/javascript">
  15. <!--
  16. <?php echo $bar->getScript()?>
  17. //-->
  18. </script>
  19.  
  20. <?php
  21. echo $bar->toHtml()
  22.  
  23. do {
  24.     $bar->display();
  25.     if ($bar->getPercentComplete(== 1{
  26.         break;   // the progress bar has reached 100%
  27.     }
  28.     $bar->incValue();
  29. while(1);
  30. ?>

Caution
As default increment of HTML_Progress is only +1(%), it may took few seconds before you could see the first cell color changed.

The empty loop was produced by a do ... while(1), with 3 HTML_Progress methods:

  • HTML_Progress::display(), to show new progress result

  • HTML_Progress::getPercentComplete(), to test end loop

  • HTML_Progress::incValue(), to ajust new progress value


  • To avoid that browser run under quirk mode, i suggest you to puts such DTD lines on each of your xHTML document.

    <!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    ...
    </html>
        

    Changing look and feel

    Progress Bar Cell element

    Here you can decide if you want to have a basic bar length (10 cells), less or more. You may also have possibility to change all the default values.

    There are 2 main methods to add and customize the cells of a Progress Bar :

  • HTML_Progress_UI::setCellCount(), more details on setCellCount Manual, where you'll find a full example.

  • HTML_Progress_UI::setCellAttributes(), more details on setCellAttributes Manual, where you'll find a full example.


  • Progress Bar Border element

    Here you can decide whether to paint or not a border, around the progress bar. You may also have possibility to change all the default values.

    There are 2 main methods to add and customize the border of a Progress Bar :

  • HTML_Progress::setBorderPainted(), more details on setBorderPainted Manual, where you'll find a full example.

  • HTML_Progress_UI::setBorderAttributes(), more details on setBorderAttributes Manual, where you'll find a full example.


  • Progress Bar String element

    Here you can decide whether to paint or not a custom string, with new value of progress bar. You may also have possibility to change all the default values.

    There are 3 main methods to add and customize the string of a Progress Bar :

  • HTML_Progress::setStringPainted(), more details on setStringPainted Manual, where you'll find a full example.

  • HTML_Progress::setString(), more details on setString Manual, where you'll find a full example.

  • HTML_Progress_UI::setStringAttributes(), more details on setStringAttributes Manual, where you'll find a full example.


  • Progress Bar element

    Here you have possibility to change all the default values (background color, width, height, orientation, fill way ...)

    There is only 3 main methods to customize a Progress Bar :

  • HTML_Progress_UI::setProgressAttributes(), more details on setProgressAttributes Manual, where you'll find a full example.

  • HTML_Progress_UI::setOrientation(), more details on setOrientation Manual, where you'll find a full example.

  • HTML_Progress_UI::setFillWay(), more details on setFillWay Manual, where you'll find a full example.


  • Prev Up Next
    HTML_Progress 1.x Tutorial HTML_Progress 1.x Tutorial Expert Guide

    Documentation generated on Mon, 11 Mar 2019 13:52:36 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.