Manuel Pear

Introduction - renderers

Introduction - renderers -- How to output the form

What are renderers?

Before release 3.0, form outputting logic was implemented as methods of HTML_QuickForm class. This led to two problems:

  1. Bloat of the said class (80+ methods!)

  2. Difficulties in adding new output logic (i.e. using template engines)

In release 3.0, new system was implemented. The form output logic is now contained in classes that extend HTML_QuickForm_Renderer, their behaviour is based on Visitor design pattern from the classic "Design Patterns" book. This gives the following advantages:

  1. Code for some particular output method is loaded only when the method is used.

  2. It is much easier to add new output method.

There are 8 renderers available since release 3.1.1, of which 2 are based on pre-3.0 code and 6 are new. The following template engines are directly suported: Smarty, HTML_Template_Sigma, HTML_Template_IT, HTML_Template_Flexy.

The main steps of using any available renderer are quite similar:

  1. <?php
  2. // include the renderer class
  3. require_once 'HTML/QuickForm/Renderer/FooBar.php';  
  4. // instantiate the renderer
  5. $renderer =& new HTML_QuickForm_Renderer_FooBar($options);  
  6. // do some customization
  7. $renderer->adjustSomething('element1', '...');  
  8. // ...
  9. $renderer->adjustSomething('elementN', '...');  
  10. // process the form
  11. $form->accept($renderer);  
  12. // output the results
  13. $renderer->toFooBar();  
  14.  
  15. ?> 
Actual methods for customization and doing the output will of course depend on renderer type.

Concerning usage examples : Usage examples provided in the manual are pretty basic. More complex examples for Default renderer can be found in docs/ directory, for all other renderers - in docs/renderers/ directory of HTML_QuickForm.


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique