Aliaspooryorik
ColdFusion ORM Book

Calling non fusebox cfm templates when using Fusebox 5.5’s Application.cfc

I’ve just encountered a problem where I wanted to run a non fusebox cfm script outside of Fusebox. If you use the Application.cfc supplied with Fusebox5.5, then it will route all requests to a cfm template through Fusebox regardless of what the template is called. As no fuseaction was specified, it just loaded the start page of my Fusebox app in the browser.

For example in my webapp root I have Application.cfc, index.cfm (both as supplied in the Fusebox 5.5 download) and another script called cgi_dump.cfm which just contains <cfdump var=”#cgi#” />. Calling cgi_dump.cfm in your browser will load the fusebox app.

One solution for this would be to put my non fusebox script in a sub folder with it’s own Application.cfc or Application.cfm which works but is a bit annoying. Rather than go for the simple solution, I had to work out a way for this to happen!

My hack for this is to edit the Application.cfc and add an onRequest method:


<cffunction name="onRequest">
    <cfargument name="targetPage" type="string" required="true" />

    <cfif ListLast(arguments.targetPage, "\/") eq myFusebox.getSelf()>
        <cfset super.onRequest(arguments.targetPage) />
    <cfelse>
        <!--- Include the requested page. --->
        <cfinclude template="#arguments.targetPage#" />
    </cfif>
</cffunction>

This checks to see the name of the called template against the known fusebox ‘hub’ template (usually index.cfm). Just to make sure that myFusebox.getSelf() is set to “index.cfm” (which it won’t be if the fusebox app hasn’t been run before), then add the FUSEBOX_PARAMETER:


// force fusebox to only run if this script is called
FUSEBOX_PARAMETERS.self = "index.cfm";

To stop the Fusebox debugging, you’ll need to also add the onRequestEnd method to your Application.cfc.


<!--- not part of the Fusebox Application.cfc --->
<cffunction name="onRequestEnd">
    <cfargument name="targetPage" type="string" required="true" />

    <cfif ListLast(arguments.targetPage, "\/") eq myFusebox.getSelf()>
        <!--- Pass request to Fusebox. --->
        <cfset super.onRequestEnd(arguments.targetPage) />
    </cfif>
</cffunction>

8 comments

  1. This doesn't work as far as I can tell. I get "Variable MYFUSEBOX is undefined". I am running the latest core files.

    Comment by Seth – May 02, 2008
  2. Hi Seth,
    I've just tested this against the fusebox skeleton apps (noxml and traditional) and can't replicate the error. Feel free to send me your code and I'll try it out.

    Comment by John Whish – May 03, 2008
  3. Yes, you're right it is working. I was putting the code into my onrequeststart() instead of onrequest(). Thank you!

    Comment by Seth – May 03, 2008
  4. Hi Seth,
    You're welcome, glad you got it working!

    Comment by John Whish – May 04, 2008
  5. Hmm, this works for calling a page outside of fusebox, but adding the onRequest method seems to break my fusebox app (coming back with a blank screen). I've been here before, but I've forgotten what it was. Is this your whole onRequest method?

    If it makes any difference, I'm using the no xml version

    Comment by Will Wilson – August 05, 2009
  6. Hi Will, just tested this against the code for this blog and it works. What does the debugging show for the called scripts?

    Comment by John Whish – August 05, 2009
  7. I've shifted the layout include to onRequestEnd and now I get an error which would suggest the view file is not being passed through.

    Here is the debugging :

    Including fusebox.init.cfm
    Compiling requested fuseaction 'app.welcome'
    Implicit component-as-circuit controller/app.cfc identified
    Parsed file 'app.welcome.cfm' is unchanged and was not overwritten
    Implicit circuit view/layout-v/ identified
    Parsed file 'do.layout-v.lay_template.cfm' is unchanged and was not overwritten
    <do action="layout-v.lay_template"/> -- dynamic  Request failed with exception 'Expression' (Variable BODY is undefined.)

    Comment by Will Wilson – August 05, 2009
  8. Variable MYFUSEBOX is undefined.
    How do you fix this error?

    Comment by kurt – June 27, 2011

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments
 

Search

Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)

Categories

Recent Posts