An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Fusebox and Application.cfc

July 23, 2007 · 8 Comments

I've seen this trip a few people up to the point that it is pretty much becoming an FAQ item so I figured I'd blog it. Scenario: You download the Fusebox 5.1 core files and then you download the Fusebox 5.1 skeleton application and then you start to build the skeleton into a real application and you decide to convert the supplied Application.cfm file to an Application.cfc file because you're a modern CFML developer. Symptom: Session variables don't work in your application! Solution: Remove the <cfapplication> tag from the skeleton application's index.cfm file. Problem explanation: As supplied - and following a long, historic tradition with Fusebox - the Application.cfm file contains only logic to trap requests to non-index.cfm files and perform a redirect. That's how Fusebox applications ensure you can't request any other CFML files. The "real" application starts with index.cfm and that begins with a <cfapplication> tag that defines the application name, session management parameters etc. When you add Application.cfc, you're overriding Application.cfm but if you pick a different application name, e.g., this.name = "myFuseboxApp"; then index.cfm promptly resets the application name and session variables set in onSessionStart() are part of a different "application" to those within the Fusebox application. This will be addressed in Fusebox 5.5 which will provide integration with Application.cfc out of the box.

Tags: coldfusion · fusebox

8 responses so far ↓

  • 1 Peter J. Farrell // Jul 23, 2007 at 8:20 PM

    I get the impression that Application.cfc support is being added for coolness.

    You dogged me on that for a while with Mach-II last fall so it only seems in good jest to dog you back. ;-)
  • 2 Sean Corfield // Jul 23, 2007 at 8:30 PM

    @Peter, definitely fair comment! :)

    The reason for Application.cfc support in Fusebox 5.5 is because XML will be optional and without XML there is no hook for the global fuseactions. Now, fusebox.appinit.cfm and fusebox.init.cfm are still available but nothing matches the postprocess fuseaction. Given that most people using Fusebox 5.5 without XML will - I believe - write their circuits / controllers as CFCs, allowing them to use Application.cfc easily seems the better approach.

    Support for Application.cfc is not in the Alpha (released to the fusebox5 Yahoo! list) but will be in the public Beta that will be available shortly.

    Your own Application.cfc will extend fusebox5.Application and, if you override onApplicationStart() or onRequestStart(), you'll need to call the super method. I'm still looking at the implications of trying to call myFusebox.do(&quot;somecircuit.someaction&quot;) within Application.cfc :)
  • 3 Calvin // Jul 24, 2007 at 8:44 AM

    While not precisely related to the post, I have always found it interesting that all ColdFusion frameworks historically have basically ignored the application framework already provided by ColdFusion.

  • 4 Sean Corfield // Jul 24, 2007 at 10:25 AM

    @Calvin, that's probably because all the frameworks existed *before* Application.cfc was introduced. Frameworks generally have to retain backward compatibility so it's not always easy to integrate Application.cfc into the fabric of the framework in a useful way *and* stay backward compatible (with both earlier versions of the framework *and* Application.cfm).
  • 5 uranio255 // Feb 10, 2008 at 9:59 AM

    I don´t understand. If you simply remove the cfapplication tag from index.cfm then you still won´t be able to use session variables... ???

    So what is the solution for this?
  • 6 Sean Corfield // Feb 10, 2008 at 10:57 AM

    @uranio255 - of course you can use session variables: Application.cfc sets up the application parameters (instead of the cfapplication tag). You need to remove the cfapplication tag because it conflicts with Application.cfc (and outside the Fusebox world people normally put the cfapplication tag in Application.cfm - which, of course, Application.cfc would override correctly).
  • 7 Sid Wood // Apr 29, 2008 at 8:01 AM

    When using Application.cfc with Fusebox, how would you bypass the framework for particular requests? I've tried putting a conditional statement around the call to super but no joy there.
  • 8 Sean Corfield // Apr 29, 2008 at 8:14 AM

    @Sid, CFC requests automatically bypass the core framework. HTML requests (via CFM pages) should go through Fusebox. Perhaps you should ask your question on the fusebox5 mailing list and provide more detail for a better answer?

Leave a Comment

Leave this field empty: