Download the EasyCFM.COM Browser Toolbar!
A brief demonstration of Fusebox 2.0

Well, first off you might be asking yourself... what is Fusebox Methodology?

Fusebox methodology is a way of creating your web site in ColdFusion (and other languages). Basically it is a way to simplify your life and to keep things much more organized. This tutorial will demonstrate a simple use of "Fusebox 2.0". Since this tutorial version 3.0 was released which is much more complicated and requires much more knowledge of it's usage. For more information visit http://www.fusebox.org

This tutorial will use the following tags, and hopefully you are familiar with them. If you are not, please familiarize yourself with those tags before completing his tutorial. The tags are:

  • <cfswitch>
  • <cfcase>
  • <cfinclude>

I will begin by creating the index page that will use these tags. The index page will contain the following text.

<!--- Index.cfm Page --->
<!--- Define the default value of "fuseaction" as home --->

<cfparam name="fuseaction" default="home">

<!--- Now create the fusebox application --->
<cfswitch expression="#fuseaction#">
      <cfcase value="home">
            <cfinclude template=
"inc_home.cfm">
      </cfcase>
      <cfcase value=
"about">
            <cfinclude template=
"inc_about.cfm">
      </cfcase>
      <cfcase value=
"contact">
            <cfinclude template=
"inc_contact.cfm">
      </cfcase>
</cfswitch>

Ok, what does all that do you ask? Let me explain. With Fusebox you will simply call one page in your browser (in your links) at all times and that page is "index.cfm". The only thing that will change will be the fusebox variable value (in blue below).

Let me show you the possible URL for this application so you can see what I mean.

  • http://ww.mysite.com/index.cfm?fuseaction=home
  • http://ww.mysite.com/index.cfm?fuseaction=about
  • http://ww.mysite.com/index.cfm?fuseaction=contact

Now, when you pass the different fuseaction values. It basically displays the correct page, because the <cfcase> will include the required file for that fuse. Now you may be asking yourself, why would I want to do this? Wouldn't it just be easier to call the pages directly and save time? Well, the answer is no!

Fusebox allows you to do many things, one of which is to keep the user in an application structure. You could add the following value on the page: (right before the <cfswitch> tag)

<cfif #SCRIPT_NAME# neq "/index.cfm">
    <!--- let user know they've access an incorrect area of the site --->
    <script>
        alert("We're sorry, you have somehow wondered out of the site struture, taking you back into it now!");
        self.location="/index.cfm";
    </script>
</cfif>

That code will basically make sure that people access only what you want them to access. Yet another ay to make your site more secure!

The other advantages of Fusebox is that it provides you with a way to keep your application organized. If you will have a members only section, you can do this withing the <cfswitch> tags.

<!--- Make sure users are logged in to access this areas --->
   <cfif IsDefined("session.isadmin") and session.isadmin eq TRUE>
      <cfcase value="admin">
            <cfinclude template=
"inc_admin.cfm">
      </cfcase>
      <cfcase value="editor">
            <cfinclude template=
"inc_editor.cfm">
      </cfcase>
   <cfelse>
    <script>
        alert("We're sorry, You need to be an administrator to access these areas!");
        self.location="/index.cfm";
    </script>
   </cfif>

In closing, Fusebox is very powerful and very scalable. This was a brief demonstration of it's usage, there are hundreds of ways to use fusebox and you can learn much more simply by going to: http://www.fusebox.org

Questions? Comments? Email me.... webmaster@easycfm.com

 

All ColdFusion Tutorials By Author: Pablo Varando