Hi guys, I'd like to know if I can solve a simple problem: I'd like to manage path like that: www.site.com/Articles/32042 as www.site.com/Articles/ViewArticle?id=32042 How can I do it?? My method "ViewArticle" is inside the Article folder. There is an easy way to do it?? My articles are loaded form a Database, so I can't create, for every article, a new Document (called with his ID) for displaing it. tnx a lot, bye
First create a zSQL method that retrieves the article content from database (selecting on the unique ID that you pass it). For example (assumes your articles table is called articles and ID field is the unique ID) select * from articles where ID = <dtml-sqlvar id type=int>; Then, in your page use a dtml-in to invoke the query for example (assumes the zSQL method is called selectArticleByID and is inside a folder called queries) <dtml-var standard_html_header> <dtml-in "queries.selectArticleByID()"> <h1>Title: <dtml-var title></h1> <h2>Author: <dtml-var authorNameFirst> <dtml-var authorNameLast></h2> <br><br> <div class="storyText"><dtml-var articleText></div> </dtml-in> <dtml-var standard_html_header> HTH, -- David On Nov 15, 2003, at 9:43 AM, Faro wrote:
Hi guys,
I'd like to know if I can solve a simple problem:
I'd like to manage path like that:
www.site.com/Articles/32042
as
www.site.com/Articles/ViewArticle?id=32042
How can I do it?? My method "ViewArticle" is inside the Article folder. There is an easy way to do it?? My articles are loaded form a Database, so I can't create, for every article, a new Document (called with his ID) for displaing it.
tnx a lot, bye
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
If you're a python product developer, you write a method called:: def __before_publishing_traverse__(self, object, request): In self.REQUEST you'll find REQUEST['TraversalRequestNameStack'] which is a list of the bits of the URL. I.e. something like ['Articles', '32042'] depending on your situation. This list you can modify on the fly to suit your needs. For example, what I do is this: Someone enters http://www.peterbe.com/oc-Zope I get a list like ['oc-Zope'] If I in this list finds something that starts with 'oc-' I pop it from REQUEST['TraversalRequestNameStack'] and deal with it separately kind of like this: REQUEST.set('onlycategory', 'Zope') Then in some other part of the site I look for the REQUEST key 'onlycategory'. For the creation of these URLs, I suggest that you wrap all URL references through some function. For example, what was: <a href="ViewArticle?id=32042"> you now do: <a href="<dtml-var "myURLFixer('ViewArticle' articleid=32042)">"> Another example (warning! extremely slow server), is http://home.peterbe.com/issuetrackers/newT/ListIssues/start-10/sortorder-urg... which I think looks better than http://home.peterbe.com/issuetrackers/newT/ListIssues?start=10&sortorder=urg... Use your imagination. On a side note, look at this URL: http://store.doverpublications.com/by-subject-science-and-mathematics-mathem... (not Zope but a nice use of this possibility) Faro wrote:
Hi guys,
I'd like to know if I can solve a simple problem:
I'd like to manage path like that:
www.site.com/Articles/32042
as
www.site.com/Articles/ViewArticle?id=32042
How can I do it?? My method "ViewArticle" is inside the Article folder. There is an easy way to do it?? My articles are loaded form a Database, so I can't create, for every article, a new Document (called with his ID) for displaing it.
tnx a lot, bye
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
.
-- Peter Bengtsson, http://www.peterbe.com
participants (3)
-
David Siedband -
Faro -
Peter Bengtsson