A Traversable Mixin Class
Make this a base class of your ZClass to make them traversable.
A Traversable object is an object that can access components
of the url as parameters.
What does it mean?
Consider the following URL:
http://www.zopesite.com/MyTraversableMethod/foo/bar
In the usual scenario, zope would search for
objects called foo and bar.
However, if MyTraversalMethod is a traversable method,
it can consume components of the url as parameters. In
the above example, MyTraversalMethod would have access
to the strings "foo" and "bar" which it can use
for any purpose.
So where you earlier used:
/Issues?priority=high&status=open
you can now use:
/Issues/HighPriority/Open
Using this mixin class, you can make any other class
traversable. Works best with DTMLDocument and DTMLMethod.
Usage Notes - Creating the ZClass
- Always make this the last base class for your ZClass
- After creating a ZClass you need to add a view:
- Go to the
Views tab of the ZClass
- Type
Traverse for the view name
- Select
manage_traverseform from the dropdown
list of available views
- The Mixin needs two properties to work. The names of
these properties are
mandatoryParameters and
optionalParameters.
You need to set them on each instance, before you
can use the traversal facilities on it. You should
tweak the ZClass_add methods to autmatically set
these properties (to 0) every time a new instance
is created.
Usage Notes - Using the ZClass
- Specify the number of mandatory and optional paramters
the method should consume. Mandatory parameters are
always consumed from the url. Optional parameters
are consumed after that only if there is no object
that can be traversed with the same id.
By default both the parameters are zero thus no url
components are consumed.
Use the Traversal tab through the management interface
to specify the number of parameters.
Why the mandatory and optional parameters?
Consider a folder F with:
- An object called
foo
- A Traversable DTML Method called
MyTMeth
Say you access the url /F/MyTMeth/foo. Should foo be
interpreted as the acquired object or should it be used
as a parameter for MyTMeth. To resolve this ambiguity
there is the concept of mandatory and optional
parameters.