MapTools.org

[Chameleon] Steps for creating your own widget?

Paul Spencer spencer@dmsolutions.ca
Tue, 10 Feb 2004 22:09:14 -0500
Dave, there is no widget developers guide (yet), I have started one but 
it is still too incomplete to send out.  I hope to have it at least to a 
state where I could send it to you in a couple of weeks.

The widgets are built on an 'object-oriented' system and Widget.php 
defines the base class for all other widgets (CWCWidget is the name of 
the class).  CWCWidget methods are those that are used by the Chameleon 
core.  Almost all have some default implementation that may or may not 
be useful.  If there is any substantial amount of code in a CWCWidget 
method, its probably not a good idea to override it :)  Many of the 
methods have very little in them, these are the candidates for you to 
replace (override) with your own implementation.

A widget file must be named WidgetName.widget.php.  The class defined in 
the widget must be exactly WidgetName (case sensitive).  The widget 
class must extend CWCWidget or some other widget that ultimately extends 
CWCWidget.  The class must define a constructor that is called 
WidgetName (a constructor is the same name as the class).  You must 
declare widget attributes in the constructor, and there are some other 
things you may wish to do there too.  Many widgets override the 
InitDefaults method to obtain values coming from the template (via the 
$this->maParams array ... basically anything that was declared as an 
attribute should be tested and assigned to class variables here).  Most 
widgets will want to overload ParseURL ... this is called for every 
widget on every page submit ... which gives you a chance to make changes 
to the map object based on input from the user ($this->moURLArray). 
Most widgets will overload at least some of the GetXXXX methods. 
Finally, DrawPublish is the method to output HTML to the page.

That's a very broad overview, but hopefully will get you started and, of 
course, there are lots of examples.  Good Luck!

Paul

Dave Astolfo wrote:

> Hi,
> 
> I am going to create a widget. I have read the documentation on doing
> so, but am still a little unclear on how to go through the steps. Can
> anyone provide a little 101 on this topic?
> 
> Questions:
> 
> 1)Upon looking at other widgets, some seem to have a common set of
> functions in them, is there a minimum set of functions that are
> required? If so, which ones?
> 
> 2)Once the widget code (php) file is created, how do you "tell"
> Chameleon or your template that it is available for use so that when I
> call <cwc2 widgetName... it will call the widget I have created?
> 
> 3)Is there a specific mechanism for including JavaScript in a widget?
> What I need to so is similar to the following:
> 
> (in pseudocode)
> 
> <?php
> 
> do php stuff here
> 
> ?>  
> 
> 
>   JSFunctionCall(parameter1, parameter2, parameterN)
> 
> 
> Thanks in advance,
> 
> 
> Dave
> 
> 
> _______________________________________________
> Chameleon mailing list
> Chameleon@lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/chameleon
> 

-- 
  -----------------------------------------------------------------
|Paul Spencer                           spencer@dmsolutions.ca    |
|-----------------------------------------------------------------|
|Applications & Software Development                              |
|DM Solutions Group Inc                 http://www.dmsolutions.ca/|
  -----------------------------------------------------------------



This archive was generated by Pipermail.