Several weeks back I was exposed to Python and Django for the first time, and it really got me thinking. While I'm not a huge fan of Python syntax, I really did like the setup for Django, and how it implements MVC. One of the first things that I loved was this little tid-bit for linking up URL requests to views:
urlpatterns = patterns('',
In that block, Django is defining regular expressions that map to Python functions, and defining how to pull named variables out of that regular expression, so that if you requested /polls/23/ becomes a call to the mysite.polls.views module to do the following:
detail(request=<HttpRequest object>, poll_id='23')
Isn't that cool? I'd love to be able to do that in ColdFusion, but it looks like there are a number of hurtles I have to get past before I can make this work:
- How do I make ColdFusion get the variables out of that URL path?
- How do I make ColdFusion look at a URL that doesn't exist?
Regular Expression Matching
First off, let me point out that CF does not natively support the (?P
Look at ColdFusion 8, there is one really nice bit of functionality that instantly jumped out at me as a very nice way to handle faux paths on a site, and that is onMissingTemplate() in an application.cfc. Theoretically, if you request a .cfm file that doesn't exist, your application is going to capture it and onMissingTemplate() will let you handle it. In actuality, its usefulness is very limited.
The onMissingTemplate() function has two big limitations, or should I say that IIS has big limitations. If you have a folder with nothing but your application.cfc, onMissingTemplate() will capture requests for any .cfm in that directory, no problem, but what if you aren't requesting a specific .cfm page (not specifying a file name), or what if you are trying to browse to a directory that doesn't exist?
In both cases IIS steps in before onMissingTemplate() can do a thing. Even if you set your default document in IIS to test.cfm, if it doesn't exist, IIS wont go there. Even though ColdFusion can handle requests for files that don't exist, IIS wont ask for your default document unless it exists. This isn't so bad really, you could just have a blank index.cfm, point IIS to it by default, and then have onRequest() and onMissingTemplate() call the same function to process them, but the next issue is the problem.
IIS wont process a request for a folder that doesn't exist. This means that you might want to use /blog/23/ as a URL, but unless the folder 23 exists in the folder blog AND you have an index.cfm in each of them, IIS will throw an error before it can get to ColdFusion.
Well, I could look for some kind of URL rewriter for IIS, but that solution will only work if you control your IIS completely, so I've ruled it out. The only other idea I have left completely depends on if long, complicated file names are any better then URL variables... I mean is "http://www.jonhartmann.com/blog.23.cfm" any better then "http://www.jonhartmann.com/index.cfm?page=blog&id=23"?