A ColdFusion Page Controller

A hate to admit it, but ever since I stopped using Fusebox a few years ago, I have been without a controller. I had my view separated from my model, but no controller to be seen. In fact, I even questioned the need for a controller on most of my projects (while seeing how it could help on larger projects). I was all ready to write a "Do I need a Controller" blog entry.

And then...

I discovered the Page Controller.

Most ColdFusion frameworks - at least the so-called MVC frameworks - are really Front Controllers. That is, they handle incoming requests and coordinate processing among multiple requests. Per Martin Fowler, a Front Controller is "A controller that handles all requests for a Web site."

A Page Controller is "An object that handles a request for a specific page or action on a Web site." (again, per Fowler).

My implementation of a page controller starts with a PageController.cfc that can be extended by each page controller. This has following methods that can be used by any page controller:

  • go (basically just cflocation)
  • param (similar to cfparam, but default kicks in instead of error for incorrect data type)
  • require (similar to cfparam, but no default or error - uses redirect for not defined or wrong data type)

The page controller itself is integrally tied to a given page. Therefore, I name it the same as the page (except the extension) and put it in the same folder). So, "about.cfm" would have a page controller called "about.cfc" (noting that this would only be for pages that need a page controller).

My view files have access to shared-scope variables (such as Application scope) and c