.Vuh files are special cases of .tcl files, used for rewriting
incoming urls. We can use a vuh file to prettify the uri for our
notes. Instead of note-edit?item_id=495
, we can use
note/495
. To do this, we will
need a new .vuh file for redirection and we will need to change the
referring links in note-list. First, add the vuh:
[$OPENACS_SERVICE_NAME $OPENACS_SERVICE_NAME]$cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/www
[$OPENACS_SERVICE_NAME www]$emacs note.vuh
Paste this into the file:
# Transform requests of type: a/b # into this internal request: A?c=b # for example, note/495 > note-edit?item_id=496 # a: base name of this .vuh file # b: from the request # A: hard-coded # C: hard-coded set query [ad_conn url] set request [string range $query [string last / $query]+1 end] rp_form_put item_id $request set internal_path "/packages/[ad_conn package_key]/www/note-edit" rp_internal_redirect $internal_path # Local variables: # mode: tcl # tcl-indent-level: 4 # indent-tabs-mode: nil # End:
We parse the incoming request and treat everything after the final / as the item id. Note that this simple redirection will lose any additional query parameters passed in. Many OpenACS objects maintain a pretty-name, which is a unique, human-readable string, usually derived from title, which makes an even better 'pretty url' than a numeric id; this requires that your display page be able to look up an item based on pretty id.
We use rp_form_put
to store
the item id in the internal register that the next page is
expecting, and then redirects the request in process internally
(ie, without a browser refresh).
Next, modify note-list so that its link is of the new form.:
[$OPENACS_SERVICE_NAME www]$ emacs ../lib/note-edit.tcl
db_multirow \
-extend {
edit_url
delete_url
} notes notes_select {
select ci.item_id,
n.title
from cr_items ci,
mfp_notesx n
where n.revision_id = ci.live_revision
} {
set edit_url [export_vars -base "note/$item_id"]
set delete_url [export_vars -base "note-delete" {item_id}]
}
You may also need to change some of the links in your package. Commonly, you would use ad_conn package_url to build the URL. Otherwise, some of your links may be relative to the virtual directory (note/) instead of the actual directory that the note is being served from.