You are not logged in Log in Join
You are here: Home » Members » shalabh » A Traversable Mixin Class » swpackage_view

Log in
Name

Password

 
 

A Traversable Mixin Class

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:
  1. Go to the Views tab of the ZClass
  2. Type Traverse for the view name
  3. 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.

  • Now in any method of your object you have a list available through the REQUEST['traverse_param'] variable.

    For example, if your object is a DTMLMethod, you can type <dtml-var traverse_param> to see the list of parameters consumed from the url.

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.

Latest Release: 0.2.0
Last Updated: 2000-06-13 01:44:05
Author: shalabh
Categories: Navigational
Maturity: Development

Available Releases

Version Maturity Platform Released
0.2.0 Development   2000-06-13 01:44:05
  TraversableMixin.tar.gz (5 K) All