now musing at www.aliaspooryorik.com!

February 15, 2008

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

Filed under: ColdFusion, Fusebox — aliaspooryorik @ 5:55 pm

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>

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.