Untitled Document
Fusebox 4.1 For Beginners Part 2
Fuseactions
Now that you have a circuit and an action for that circuit you will want to create the page that will be that action. If you just said "huh?" don't worry it will become clear in a moment. Open up your favorite editor and create a page called dsp_welcome.cfm. In that page I would like you to type the phrase "Hello, I am an action called "welcome"." Save it to the same folder as your index.cfm file is in. Once that is done open up index.cfm in your browser again. Go ahead I'll wait for you.
If you are cursing up a storm because you received a error message that read something like this, "The circuit xml file, circuit.xml, for circuit Main could not be found" you have done everything correct so far and can stop cursing. So what happened? Well the short of it is that we have set up a circuit called main and an action of welcome that is our default fuseaction, but we haven't specified what the action should do. So we want to specify that our action is to open up the dsp_welcome.cfm page. We do this by opening the circuit.xml.cfm document and placing the following text there between the fuseaction tags we added:
<include template="dsp_welcome.cfm" />
Your file should now look like this:
Circuit.xml.cfm
<circuit access="public">
<fuseaction name="Welcome">
<include template="dsp_welcome.cfm" />
</fuseaction>
</circuit> |
Ok once you have that done save and open up index.cfm in your browser again. Go ahead I promise it will work correctly now. If you have done everything exactly as I have it you should see that the dsp_welcome.cfm is showing. But how is this possible? Everything goes through the index.cfm page. This provides for better security along with easier control. And since main.welcome is your default fuseaction you will always see this page if you type in index.cfm. Go ahead and try to open dsp_welcome.cfm in your browser see what happens. It automatically calls back up the index.cfm page. So how is this possible. Open the application.cfm page.
In it you will see this:
<cfif right(cgi.script_name, Len("index.cfm")) NEQ "index.cfm" AND right(cgi.script_name, 3) NEQ "cfc">
<cflocation url="index.cfm" addtoken="no">
</cfif>
This keeps any page, but the index.cfm page from being opened providing security for your scripts, because now a user will no long see the name of the page being called! What a great idea!
Ok now that we have a basic hello page lets beef it up. Open up dsp_welcome.cfm we want to make it go to another page call dsp_yourname.cfm, but we want it to actually say a persons name. So we will insert a form. On the dsp_welcome.cfm page type the following:
<form action="index.cfm?fuseaction=main.DisplayName" method="post">
<input type="text" name="name">
<input type="Submit" value="submit">
</form>
So your dsp_welcome.cfm page should look like this:
dsp_welcome.cfm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="index.cfm?fuseaction=DisplayName" method="post">
<input type="text" name="name">
<input type="Submit" value="submit">
</form>
</body>
</html> |
Now look at the form action. We call the index.cfm page and we pass a variable called fuseaction with a value of DisplayName. So how do we call the dsp_yourname.cfm page we are about to make? If you said by placing some script in the circuit.xml.cfm page you are correct and probably should not be reading this tutorial. ;-) Really we want to open the circuit.xml.cfm page and place the following code there:
<fuseaction name="DisplayName">
<include template="dsp_yourname.cfm" />
</fuseaction>
So now your circuit.xml.cfm looks like this:
Circuit.xml.cfm
<circuit access="public">
<fuseaction name="Welcome">
<include template="dsp_welcome.cfm" />
</fuseaction>
<fuseaction name="DisplayName">
<include template="dsp_yourname.cfm" />
</fuseaction>
</circuit> |
Ok now create a new page and name it dsp_yourname.cfm. In it put the following code:
<cfoutput>Hello my name is: #Form.Name#.</cfoutput>
Now open index.cfm in your browser. You should see the newly created form. Type in your name and click submit you should now see your name and the hello message. If so great! You have done everything correct so far. If not go back over your code and match it exactly to mine.
Now it is time to get a little more advanced with this and start experiencing the power behind fusebox. So go to the potty, get yourself your favorite drink, and buckle your seat belts then move on to part three of this series.
Date added: Mon. July 4, 2005
Posted by: Craig | Views: 16004 | Tested Platforms: CFMX,CFMX7 | Difficulty: Beginner
Best Practices
 |
url rewrite doesn't work
The application.cfm script doesn't work. I keep getting 'fuseaction=' appended to the index.cfm. I've tried some of the demo fusebox apps that include it and the script doesn't work properly with them, either. Any ideas?
Posted by: Chris
Posted on: 07/19/2005 11:16 PM
|
RE:url rewrite doesn't work
Chris, did you download fusebox 4.1 or are you writing the aplication.cfm? Cause you really don't touch application.cfm in this tutorial at all either than to look at it.
Posted by: Craig
Posted on: 07/20/2005 09:15 AM
|
RE:url rewrite doesn't work
I downloaded 4.1 from fusebox, installed in my wwwroot directory. I have not made any changes to application.cfm. I've tried this on two different machines and keep getting 'http://localhost/demoapp/index.cfm?fuseaction=main.CountingLoopBackward' on the address line.
Posted by: Chris
Posted on: 07/20/2005 10:18 AM
|
RE: url rewrite doesn't work
Ok. I don't understand what the problem is. If you are concerned about the fuseaction showing in the url that is exactly what it is suppose to do. The rewrite is for when someone tries to open a page like lets say home.cfm. The rewrite says "Hey wait a minute the only page allowed to be opened is index.cfm so let me redirrect this user to index.cfm." Thus protecting your scripts from prying eyes. Let me explain this a little better. Ok let just say you have a page called home.cfm inside your fusebox app. Now that page holds your database names for a database that contains credit card numbers. Now just fyi there are programs out there that can pull your source code in cfml dirrectly off your server. The person who decides I want databse names so I can get the cc info uses that program on your home.cfm page now they have the database names and can make their own script to pull information out of them. (Yes it can be done.) Now here were the security of fusebox come in. Since you are not naming anything but your index page and the fuseaction they don't know the name of your home.cfm page or where to look for it. Thus protecting your databse names. So instead of seeing URL: mywebsite/home.cfm the only thing you see is URL: mywebsite/index.cfm?fuseaction=myfuse.myaction If a person with the type of program I explained about tries to pull the script all they will get is the script you find on the index.cfm page. They will never know the fuseaction is for home.cfm to be called. Its like working for the cia everything has a code name and thus protecting the real identity. Does that help explain it to you?
Posted by: Craig
Posted on: 07/20/2005 10:47 AM
|
try this
Try opening a page either than the index.cfm in your browser and see what happens this is the what the application.cfm page does and you can see it in action.
Posted by: Craig
Posted on: 07/20/2005 10:50 AM
|
Form action should be index.cfm?fuseaction=main.DisplayName
Craig... your fusebox tutorial is really great. It's really made this stuff simple to understand.By the way, I think there is one small typo. I'm thinking the form action should be "index.cfm?fuseaction=main.DisplayName" instead of just "index.cfm?fuseaction=DisplayName".
Posted by: Jansen Rensma
Posted on: 08/10/2005 11:46 AM
|
RE: Form Action
You are absolutly right. It is a typo. Sorry if this confused anyone. I wrote these tutorials one night when I couldn't sleep so I am surprised there aren't more. Thank you also for the comment about the tutorial I am glad it has explained it well for everyone, cause I know how little there is out there about fusebox 4 and most of it is from the fusebox.org website but it isn't in plain english. I'm happy to help.
Posted by: Craig
Posted on: 08/10/2005 03:46 PM
|
<form action="index.cfm?fuseaction=DisplayName" method="post">
should be:
<form action="index.cfm?fuseaction=main.DisplayName" method="post">
Let me know if this isn't right.
Thanks!
Posted by: James
Posted on: 11/14/2005 05:51 PM
|
|