Many Fusebox developers set a variable called "self" which they use in their links. In most cases, this points back to the root index.cfm file. But the nice thing about using #self# instead of a hardcoded reference is that it is simple to change the name of this file, or to make unit testing easier. This is often done in the new fusebox.init.cfm file when using Fusebox 4.1.

Along the same line, some folks are now using a variable called "mySelf" that contains not only "index.cfm" but also the fuseaction variable name. Doing this makes changing your fuseaction variable (say from "fuseaction" to "method") very easy:

<cfset mySelf = "#self#?#application.fusebox.fuseactionVariable#=" />

If you used it like this:

<a href="#mySelf##xfa.backHome#">Return Home</a>

You'd end up with something like this:

<a href="index.cfm?fuseaction=home.main">Return Home</a>

Well I realized that with a little more tweaking, #mySelf# could also decide whether to append an ID and token to the URL by using the URLSessionFormat() function. If you aren't aware, this function will automatically append the CFID/CFTOKEN or JSESSIONID to the URL if the user does not allow cookies. I did it like this:

<cfset mySelf = "#urlSessionFormat( '#self#' )#" />

<!--- Workaround for IIS problem with JSessionID: http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=1c6b723 --->
<cfif findNoCase( 'index.cfm;', mySelf )>
   <cfset mySelf = replace( mySelf, 'index.cfm;', 'index.cfm?' ) />
</cfif>

<cfif right( mySelf, 9 ) eq "index.cfm">
   <cfset mySelf = mySelf & "?" />
<cfelse>
   <cfset mySelf = mySelf & "&" />
</cfif>

<cfset mySelf = mySelf & "#application.fusebox.fuseactionVariable#=" />

It's a little more complex than one thinks it should be because of how the function appends the token in different situations. But that's what it took to get it to work in my tests. That said, it seems to work very nicely!

Comments Comments (1) | del.ico.us del.icio.us | Digg It! Digg It! | Linking Blogs Linking Blogs | 3650 Views

Comments

  • # Posted By Julian | 3/5/05 3:10 AM

    Brian, I hit on the same idea a while ago and came up with a slightly simpler workaround for handling the &quot;?/&amp;&quot; issue.

    http://www.fusebox.org/forums/messageview.cfm?cati...

    I'm still not 100% happy with it as a cookie checker though... If you use the URLSession'ed mySelf variable in a cflocation to redirect initial visitor hits from a subdirectory (eg mysite.com/articles/) you seem to get tokens appended regardless of the browser's cookie setting - which then persist in all your links.

    But apart from that, if hou have to support cookie-less sessions (and clients are happy to accept bloated/insecure URLs) then this technique certainly offers a nice bit of synergy between FB and CFMX.