Fusebox 4.1 For Beginners Part 1
What is Fusebox? Circuit.xml.cfm and Fusebox.xml
Fusebox is a powerful and easy way to create dynamic sites and large programs for the web. It allows multiple users to work on the same project at once without worrying about each others code (as long as the basics are known such as db name and where images are stored, etc). It is also a great way for single coders to create powerful and compelling web sites and programs with ease. What makes fusebox coding so great is its simplicities of coding. You can create just small little files and maintain them easily and effectively. Also with fusebox if one part of your program or site is broke or not working it doesn't affect the rest of your site or program.
We all know what a fusebox is. If you own a computer you are using a fuse box right now. It's usually located in a basement or closet and it allows you to cut the power to any given room or rooms you would like. If you accidentally drop your hairdryer into the tub a fusebox will have a fuse blow protecting you from sudden death (hopefully). It is the same idea behind fusebox 4.1.
To follow this tutorial please go to http://www.fusebox.org and download your copy of fusebox 4.1 and unzip it to your wwwroot folder. Once you have that done we can begin.
Open up your favorite code editor (I am using dreamweaver but any will do.) and create a file called circuit.xml.cfm. Save it to the same folder as your index.cfm file is in.
Now this file is sort of like the brain of the fusebox. It will house the information that each circuit will do. But before we get into that lets put some code in here. Place the following code into the circuit.xml.cfm page.
If you're rubbing your temples and scratching your head at this don't worry you are not going crazy. This is XML in a CFML document without the use of cfsavecontent tag. If you are wondering what cfsavecontent is don't worry about it now you won't need it for this tutorial series.
Ok now that we have the basic for circuit.xml.cfm laid out lets open the fusebox.xml document you have unzipped. Now take a minute to study this document. It is an XML document. The first tag opens the fusebox. The next tag you see is the <circuits> tag. Notice that it also has a closing tag and that there is nothing in between. Now go down the page a little bit and you will see some more tags that are called "parameter" You will see 14 of them. Now if you are reading through them your head is probably starting to hurt. I know mine did at first.
Don't worry what they all mean just yet. Let's just focus on the one with the name of "defaultFuseaction". Notice that the value is "main.welcome". Ok now if you have a testing server running cfmx 6 or above open up index.cfm that was included in the fusebox 4.1 download and open it in your browser. You should see a error message that says something along the lines of, " You specified a Circuit of main which is not defined." So what happened? The index page is the main controller of everything in your fusebox. It is the box that makes up your fusebox. Every single item has to pass through the index.cfm page. So why isn't it working? It is not working because we have no circuit called main. Let me take a moment to explain something here before we fix our broken circuit.
Your circuits can be named anything you would like them to be as long as it is not something reserved by coldfusion. In this case our circuit is named main. It was defined in the fusebox.xml document set in the parameter named "defualtFuseaction". It looked like this main.welcome. So what happened to the welcome? The welcome is the fuse action. It is what the circuit main does. So it would read something like this to a server. The user would like to view the circuit main and the action this circuit is to perform for the user is welcome.
Ok now that we have explained this lets fix the broken circuit. First step we must take is to create the circuit main. Go back to your fusebox.xml document and go back up to the circuits tag. Now type in between the opening and closing circuit tags the following:
<circuit alias="Main" path="" parent="" />
<circuit alias="Main" path="" parent="" />
What we just did was created a circuit called main. NOTE: Remember that everything in XML must have a closing tag.
Once you have done that open circuit.xml.cfm and place this following code in it making sure you place it in between the circuit tags:
<fuseaction name="Welcome"> </fuseaction>
Now you have created the circuit and the action it is to do!
Once this is completed move on to the second part of the tutorial.