[Zope] Zope Question : Virtual folders / URL's

Michel Pelletier michel@digicool.com
Thu, 09 Mar 2000 17:27:11 -0800


Ian Sparks wrote:
> 
> Thanks again Mike.
> 
> So my final (I think, for now) question is this :
> 
> The whole point of Zope is to get a result back so the URL :
> 
> mysite.com/Users/Fred/Flavor/Cherry/rss
> 
> is (the way we have discussed it) really a way of saying : "I want an "rss"
> document containing information related to User=Fred, Flavor=Cherry.
> 
> So in order to get my content out I just have to do some things with
> <dtml-with Users> and <dtml-with Flavor> in my "rss" document?

You don't even have to work that hard, consider what happens:

Let's say that your Users method queries a table that contains two
columns, name and title.  Primary key is 'name'.

Your second method queries a table that contains two columns, flavor and
size.  Primary key is 'flavor'.

Users method is called with 'Fred' as argument, this returns a single
record object.

ZPublisher then tries to find 'Flavor' on that record object, it doesn't
have such an attribute, but it CAN acquire it, so it does.  It discovers
that it is a SQL method and calls that method, *in the context of the
first record object* (keep that in mind...).

The second method is called with 'Cherry' as a argument.  It returns a
single record object.  Now, ZPublisher tries to find 'rss' in that
record object and fails, but it DOES acquire it, *in the context of the
second record object which was found in the context of the first*.

Now you are in the rss method, but you are also in the context of the
second and first result objects, in that order.  So in your method, just
say:

Hi my name is <dtml-var name>.     I'm acquired from the first result
object.
My title is <dtml-var title>.      I'm acquired from the first result
object.
The flavor was <dtml-var flavor>.  I'm acquired from the second result
object.
The size was <dtml-var size>.      I'm acquired from the second result
object.

Note that if a subsequent record object has a column name identical to
that of a preceding record object, the subsequent one is acquired
first.  This means that subsequent results can 'refine' previous ones.

Note that this concept of accessing one object in the context of another
is what is called Acquisition and all Zope objects support it, not just
ZSQL Methods.

-Michel