Widget Construction Tutorial
Step 1 - The BaseWidget
The BaseWidget class is used as a parent
class to most Widgets. It provides some
common methods/variables used among most
of the widgets I have created. The BaseWidget
class is declared in phphtmllib/widgets/BaseWidget.inc.
What does the BaseWidget provide?
First of all, it provides a common set of APIs
for building the widget, adding data to it, and
then rendering the output. This makes it easy
to be familiar with how to use several different
kinds of widgets that do different things.
Important Methods to override from BaseWidget.
- This method
exist for each widget. It is the common method
that each of the
assumes exists for each object/widget. This method
is automatically called by a parent object's render()
method. This enables you to add a widget to another
widget using the add()/push() method(), and rendering the
widget will get done automatically in the right order/place
the person expects it to be.
- This method is the common API to call
for adding content/data to a widget. It is not uncommon for
a widget to provide several specialized methods for adding
content/data to itself, but it's a good idea to at least
provide the add() method to make the API consistent with other
There are several other methods that the BaseWidget provides
for various things. You will want to check out the
JavaDoc API Section
for all the details of what the BaseWidget provides.
The BaseWidget provides methods for getting/setting the
title of the widget (if used at all by the child) with
It also provides a set of methods to get/set the width
of the widget (if used by the child at all) with the