I usually have an XML file that defines the URI stems for any given 'page' in the application.
The URI stem will include all URL variables that are required for that page, so you might have an xml file entry that looks like this:
<invocation>
<id>products.showproduct</id>
<uristem>index.cfm?page=2</uristem>
<var required="true" type="numeric" name="productid" />
<var required="false" type="string" name="mode" defualt="summary" />
<component>products</component
<method>showProduct</method>
<navcontext branch="home" />
<role>guest</role>
</invocation>At application startup, all the entries in the XML file are loaded into a URIAbstractor component. That component is then passed to all ui layer
templates and they call abstractor.getURI() passing the ID and a struct containing name value pairs for any url variables.
So you might have something like this:
productlisting.cfm
<cfparam name="attributes.products" type="query" required="true" />
<cfparam name="attributes.uriAbstractor" required="true" />
<cfset params = structNew()>
<cfloop query="attributes.products">
<cfset params.productid=attributes.products.productid>
<a href="#attributes.uriAbstractor.getURI("products.showProduct",params)#">#attributes.products.productName#</a><br />
</cfloop>
There are a few pros to doing this.
1. The URL for the showProduct page is completely abstracted from every part of the application except the xml file and the URI abstractor cfc.
2. All the valid URI stems in your application can be viewed and administered in a single XML file.
3. You can set up and view roles based access in the xml file which makes it easier to keep track of what's going on.
4. You can specify the nav context so you know what nav node to highlight when on any given page.
It won't fit the mould for every application, but for some it does.
Spike
Patrick Mcelhaney wrote:
Hi Folks,
I have a CFC that writes HTML code including some anchor tags. I don't
want the CFC to know how to write the links. That decision really belongs to the layer that calls it. I don't want the CFC to be coupled to:
1. The Fusebox framework 2. The name and location of the controller page (/index.cfm)
3. The fact that there is a controller page at all
4. The fact that I'm using "&" to delimit parameters (not search-engine-safe)
5. The names of the fuseactions that relate to each exit point
6. The names of the URL parameters
Using a variable called "self" instead of hard-coding "index.cfm" takes care of #2. Hal's XFAs take care of #5. These are both old ideas from circa CF 3.1. I'm sure that we can fully abstract the way links are written using CFCs. I'd be surprised if a lot of people aren't already doing that. I just don't know where to look.
This morning in the shower I brainstormed a "ExitPoint" component that would keep track of a set of exit points and how to write the links for those exit points.
First initialize the exitPoints object and tell it to write links Fusebox-style. exitPoints = createObject("component", "ExitPoints"); writer = createObject("Component", "FuseBoxExitPointWriter"); writer.init("/index.cfm", "fuseaction") exitPoints.setWriter(writer):
Then define the exit points. exitPoints.add("createPerson", "ppl.newPersonForm"); exitPoints.add("selectPerson", "ppl.editPersonForm", "personID"); exitPoints.add("removePerson", "groups.dropPerson", "personID", "groupID");
The first argument of the add method is the name of the exit point.
The second argument is the name of the action. (In this case it's a fuseaction, but it could be an event, page name, etc.) The rest of the arguments are paramters that must be passed out of the exit point.
Here's how the exit points would be used:
<a href="#exitPoints.write('createPerson')#">Create Person</a><br> <cfloop query="people"> <a href="#exitPoints.write('selectPerson', people.id)#">#people.name#</a> <a href="#exitPoints.write('removePerson', people.id, groupID)#">[remove]</a> <br> </cfloop>
Here's what the resulting HTML would look like:
<a href="/index.cfm?fuseaction=ppl.newPersonForm">Create Person</a><br> <a href="/index.cfm?fuseaction=ppl.editPersonForm&personID=1">Bob</a> <a href="/index.cfm?fuseaction=groups.dropPerson&personID=1&groupID=4">[remove]</a> <br> <a href="/index.cfm?fuseaction=ppl.editPersonForm&personID=2">Larry</a> <a href="/index.cfm?fuseaction=groups.dropPerson&personID=2&groupID=4">[remove]</a> <br>
Again, I won't be surprised if something like this is already a common practice. I would appreciate if someone would point me in the right direction.
--
-------------------------------------------- Stephen Milligan Code poet for hire http://www.spike.org.uk
Do you cfeclipse? http://cfeclipse.tigris.org
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
