Menu

As simple as possible, as complex as necessary

Upgrading to FW/1 2.5

14 July 2014

Almost 2 months since the release of FW/1 2.5, I've just got round to upgrading my apps, most of which were running version 2.2.

Two features of the framework have now been deprecated and turned off by default:

  1. the service() queuing system for "teeing up" calls to the service layer;
  2. the ability to reference the rc (request context) "scope" prior to the beginning of the controller phase of the request.

Don't make me wait

The first is of no consequence to me since I've always preferred to manage my own services rather than call them via the framework. Coming from Fusebox, I never understood why you'd want to be railroaded into not allowing service calls to actually execute until after your controller code had run. And I found the whole startItem/endItem thing just baffling.

I appreciate the idea was based on a set of assumed conventions and a strict interpretation of MVC with ultra-thin controllers, but in the real world I want my services to execute as soon as I call them so that my controllers can act on the results if they need to.

Global before()

The second change does require some code modification if like me you are in the habit of referencing the rc struct in Application.cfc.

void function setupRequest(){
 rc.someGlobalValue = "x";
 rc.anotherGlobalValue = "y";
}

setupRequest() has always seemed a logical place to initialise values I want to be globally available in the request context. Apparently though, this should be done later in the request lifecycle using a global function of which I wasn't previously aware: before() in Application.cfc.

void function before( rc ){
 rc.someGlobalValue = "x";
 rc.anotherGlobalValue = "y";
}

I could have avoided the need to make even this small adjustment by adding a backward-compatibility option to my configuration (enableGlobalRC=true). But since these deprecated features will be removed in version 3.0, it's sensible to prepare now, especially given how straightforward this particular change is.

Small but useful

Finally, a tiny but pleasing new addition to the FW/1 API is the isCurrentAction() function. There may be other use cases, but navigation is the obvious area which stands to benefit.

In several of my apps, I've been able to improve the legibility of the logic which applies different styling to the currently selected navigation menu item:

...
<cfset local.class = ( getFullyQualifiedAction() IS "main.about" )? "currentNavLink": "navLink">
<li><a href="/about" class="#local.class#">About</a></li>
...
...can be re-written:
...
<cfset local.class = isCurrentAction( "main.about" )? "currentNavLink": "navLink">
<li><a href="/about" class="#local.class#">About</a></li>
...
Thanks Sean (and Nathan who requested the enhancement).

Posted on . Updated

Comments

  • Formatting comments: See this list of formatting tags you can use in your comments.
  • Want to paste code? Enclose within <pre><code> tags for syntax higlighting and better formatting and if possible use script. If your code includes "self-closing" tags, such as <cfargument>, you must add an explicit closing tag, otherwise it is likely to be mangled by the Disqus parser.
Back to the top