[Zope] Re: Constructing 'Friendly' URLs in products
Tonico Strasser
contact_tonico at yahoo.de
Thu Dec 2 09:12:47 EST 2004
Phillip Hutchings wrote:
> Hi,
>
> I'm fairly new to Zope, so if it's a obvious answer don't kill me ;)
>
> I've been considering setting up a blog in Zope. I used to use
> Wordpress in PHP before I decided to give Zope a try, and I'm actually
> liking it so far.
>
> Anyway, I've looked at coreblog, but it gives URLs like /blog/12 and
> /blog/1234, I'm really looking for things like
> /blog/2004/11/04/wow-zope-is-cool, like Wordpress manages with the aid
> of mod_rewrite.
>
> Now, I guess I could do somthing like
> /blogposts?year=2004&month=11&day=04&title=wow-zope-is-cool through
> mod_rewrite, but I was wondering if there was a more zope-centric
> solution? About the best I could come up with was chaining a series of
> persistant classes which subclass Item.Folder (iirc that's the one),
> sort of like this:
> Blog->BlogYear(id=2004)->BlogMonth(id=11)->BlogDay(id=04)->BlogPost(id=wow-zope-is-cool),
> just a containment hierarchy. Is this good or bad thinking? I was also
> thinking of a single class that used something like __getattr__ to
> process a function or something, but I haven't though of how that
> would work. Probably like this myPosts =
> {'2004':{'11':{'04':{'wow-zope-is-cool':getBlogPost}}}}, but I'm not
> sure if that would even work.
>
> Comments? Suggestions?
Hm. If your url structure is always
blog / year / month / day / name
you could make 'blog' a method that parses the 'traverse_subpath' and
returns the corresponding object.
'traverse_supbpath' is a sequence in the REQUEST object that contains
the parts of the url after the methods name. e.g.
['2004','dec','02','hello']
HTH.
Tonico
More information about the Zope
mailing list