Art site: Parsing the URL for SES
For this art website, there are categories of art and there are pieces of art. If you're looking at some art in the Mackinac category, my options were
art.cfm?category=dmackinac&art=harbor
art.cfm/mackinac/harbor
and of course the third is easiest to read and understand. That is to assume that any average web user ever looks at the URL. The third is called "search engine safe" (SES).
To accomplish this, you have to parse the URL string. In most web server environments, anything passed with and after the file name goes into the cgi.path_info variable. cflib.org has a parseSES() function, but it was wasn't exactly what I wanted. I wasn't passing name-value pairs in the URL, just values. Unless someone is hacking the URL, the category will always be first, then the art name. So I changed the parseSES() function to return the stuff passed in the URL as an array as well as the name-value pairs.
<cfscript>
var LOCAL=StructNew();
LOCAL.pathInfo = reReplaceNoCase(trim(cgi.path_info), '.+\.cfm/? *', '');
LOCAL.i = 1;
LOCAL.lastKey = "";
LOCAL.value = "";
LOCAL.url = StructNew();
LOCAL.urlArray = ArrayNew(1);
if(not len(LOCAL.pathInfo)) return LOCAL;
for(LOCAL.i=1; LOCAL.i lte listLen(LOCAL.pathInfo, "/"); LOCAL.i=LOCAL.i+1) {
LOCAL.value = listGetAt(LOCAL.pathInfo, LOCAL.i, "/");
ArrayAppend(LOCAL.urlArray, LOCAL.value);
if(LOCAL.i mod 2 is 0) LOCAL.url[LOCAL.lastKey] = LOCAL.value;
else LOCAL.lastKey = LOCAL.value;
}
Çspan style='color: #808080'ÈÇemÈ //did we end with a "dangler?"
Ç/emÈÇ/spanÈ if((LOCAL.i-1) mod 2 is 1) LOCAL.url[LOCAL.lastKey] = "";
return LOCAL;
</cfscript>
</cffunction>
So on to the implementation! In Application.cfc, in the OnRequestStart() method, first thing is to call urlvars=parseSES(). From the length of the array of values returned in that, I know what the user's trying to do.
ArrayLen(urlvars.urlArray) eq 1 category selected
ArrayLen(urlvars.urlArray) eq 2 art selected
I went as far as querying for all the category and art details in OnRequestStart. This worked out well because then the category and art names were available when I printed the page title.
Next: Where to put images

