Title: Fusebox%20Not%20Just%20For%20Breakfast%20Anymore!
1FuseboxNot Just For Breakfast Anymore!
- An Introduction to Fusebox
- Author Fred T. Sanders, Instant Knowledge
- Some Content unscrupulously taken from
- Steve Nelson, Hal Helms and Nat Papovich
2Prerequisites to Fusebox
- Some CFML basics to under before looking at
Fusebox - ltcfparamgt and ltcfsetgt
- ltcfincludegt
- ltcfmodulegt - custom tags
- ltcfswitchgt - ltcfcasegt
- ltcfapplicationgt
- ltcfquerygt
- ltcflocationgt
- Variable scopes server/application/request/client
/session/attributes/caller - URLToken
- ASK if you do not understand any of these tags
3A CF Developers Holy Grail...
- Imagine
- A team of developers writing code that looks like
it came from one individual. - You could understand your co-workers code in 5
minutes, without asking them questions. - You could spend more time solving your problems
instead of worrying about how to write the
application. - You could actually build a library of generic
reusable code and eventually be able to cut and
paste the backend of almost all your new
applications. - Well dont pinch
yourself yet!
4What Could You Gain with Fusebox?
- A flexible application framework for building web
applications, that is easy to work with. - A collection of best practices and free tools
designed to speed up the development cycle and
shorten the time to market for most of your
projects. - Easy to learn. You are most likely using many of
the methods shown today, and never realized it.
Adopt as much or as little as you want. - Flexible and extensible. There is no Fusebox
Gestapo to make sure you followed the rules,
because there arent any. - Hopefully more free time or less stress. (I said
Hopefully!).
5Why A Structured Application Framework?
- File based applications get messy. A structured
application framework helps to clean the mess
up. - Team development is easier to facilitate.
- Your application will almost document itself.
- Youll only have to focus on your clients
problems and not have to worry about how to
structure your application.
6Size Does Count!Sometimes Smaller Is Better.
Break down your one big application into little
Circuit applications.
Circuits
?
/members
Home
?
?
/products
?
/shoppingcart
7Break It Down Further
Turn each circuit into many Fuseactions
Circuits
This is Meant to Be Just text That isnt Clear. I
hope It works the Way I want It to.
AddUser
Home
?
This is Meant to Be Just text That isnt Clear. I
hope It works the Way I want It to.
Login
This is Meant to Be Just text That isnt Clear. I
hope It works the Way I want It to.
?
List Products
?
This is Meant to Be Just text That isnt Clear. I
hope It works the Way I want It to.
View Product
This is Meant to Be Just text That isnt Clear. I
hope It works the Way I want It to.
AddtoCart
?
This is Meant to Be Just text That isnt Clear. I
hope It works the Way I want It to.
CheckOut
8The FuseBox (index.cfm)
- The Applications Center of the Universe
- Just one big ltCFSWITCHgt Statement.
- Calls the Fuses needed based on which
fuseaction is being performed.
9The Fuseaction
- Defines what the user wishes to do.
- Calls as few or as many fuses as needed.
- Will not always display output to the user.
- Controls the flow of the application.
- Always Returns back to the Fusebox.
10A Fuse
- Could contain CFML, HTML, or even JavaScript
code. - Helps to separate business logic from the User
Interface. - Helps facilitate code re-use within the
application.
11Quick Review
- Home Application The overall site.
- Circuit Application A smaller, more specialized
application. - Fusebox The glue of the application. Everything
revolves around the Fusebox. - Fuseaction An individual task within the
Fusebox. - Fuse The code necessary to perform what the
task defined by the fuseaction.
12Application Files
- Used for setting Home application-wide
variables (variables used in multiple circuit
applications) - Use the request scope for common global
variables. It is thread safe unlike the
application scope which requires ltCFLOCKgt.
13Action Files
- Perform background tasks.
- Inserting Records.
- File handling.
- Sending email.
- Does not output anything to the user.
14Display Files
- Contains both HTML and CFML, or any other display
language like WML. - These files display information to the user.
- Search Engine Results.
- Query Results.
- Static Information.
- Common Forms.
15Query Files
- Makes re-using common SQL code easier.
- Helpful with cached queries. You can refresh
them by simply calling the qry_filename.cfm again.
16URL Files
- Used for redirecting the user to another
page/fuseaction after theyve finished an action
file. - Helps Protect against a user hitting the reload
button on their browser and duplicating data on
the server.
17Calling A Fuseaction
- Call your Fuseactions from the URL, Form or even
Attributes in a custom tag - http//www.fusebox.org/index.cfm?fuseactiondelete
- ltinput name"fuseaction" type"hidden"
value"delete"gt - ltcfmodule template/yourdirectory/index.cfm
fuseaction"delete"gt - All links and forms will point to Index.cfm
18Naming Conventions
- To make life easier use naming conventions.
- App_filename.cfm Application files.
- Act_filename.cfm Action files.
- Dsp_filename.cfm Display files.
- Qry_filename.cfm Query files.
- Url_filename.cfm Redirection files.
- Or DEFINE your own meaningful conventions.
19Scoping Your Variables
- URL FORM variables need to be scoped to
ATTRIBUTES. (ltCF_FORMURL2ATTRIBUTESgt will do this
conversion for you). - Use the REQUEST scope for your global variables.
- Using Client instead of the Session scope makes
application scaling easier later on.
20Code Example 1
- Demonstrates a Fusebox application made of 4
files, one Fuseaction which displays - Hello World and another which displays
Good-Bye Cruel World
21Example Code 1 Index.cfm
lt!---Index.cfm---gt ltcfinclude templateapp_globa
ls.cfmgt ltcfparam name"attributes.fuseaction"
default""gt ltcfswitch expression"attributes.fus
eaction"gt ltcfcase valuegoodbyegt
ltcfinclude templatedsp_goodbye.cfmgt
lt/cfcasegt ltcfdefaultcasegt
ltcfinclude template"dsp_hello.cfm"gt
lt/cfdefaultcasegt lt/cfswitchgt
22Example Code 1 app_globals.cfm
lt!--- app_globals.cfm ---gt ltcf_formURL2attributes
gt
23Example Code 1 dsp_hello.cfm
lt!--- dsp_hello.cfm ---gt lthtmlgt ltbodygt lth1gtHello
World!lt/h1gt ltPgt lta hrefindex.cfm?Fuseactiongood
byegtGood-Byelt/agt lt/bodygt lt/htmlgt
24Example Code 1 dsp_goodbye.cfm
lt!--- dsp_goodBye.cfm ---gt lthtmlgt ltbodygt lth1gtGood
-Bye Cruel World!lt/h1gt ltPgt lta hrefindex.cfm?Fuse
actionhellogtHello!lt/agt lt/bodygt lt/htmlgt
25Code Example 2
- Demonstrates a Fusebox application made of 7
files and 3 fuseactions. This allows for viewing
a list of names and adding a new name in a
database.
26Example Code 2 Index.cfm
lt!---Index.cfm---gt ltcfinclude templateapp_globa
ls.cfmgt ltcfparam name"attributes.fuseaction"
default""gt ltcfswitch expression"attributes.fus
eaction"gt ltcfcase valuenameformgt
ltcfinclude templatedsp_nameform.cfmgt
lt/cfcasegt ltcfcase
valueaddnamegt ltcfinclude
templateact_addname.cfmgt
ltcfinclude templateurl_listnames.cfmgt
lt/cfcasegt ltcfdefaultcasegt
ltcfinclude templateqry_getnames.cfm"gt
ltcfinclude template"dsp_listnames.cfm"gt
lt/cfdefaultcasegt lt/cfswitchgt
27Example Code 2 app_globals.cfm
lt!---app_globals.cfm---gt ltcf_formURL2attributesgt
ltcfapplication nameexample2
clientmanagementyesgt ltcfset request.urltoken
client.urltokengt ltcfset request.mainDSN
mydatabasegt
28Example Code 2 qry_getnames.cfm
lt!---qry_getnames.cfm---gt ltcfquery name
qryGetNames datasource request.maindsn
datatype ODBCgt SELECT User_ID,
first_name, last_name FROM
Users lt/cfquerygt
29Example Code 2 dsp_listnames.cfm
lt!---Dsp_ListNames.cfm---gt lthtmlgt ltbodygt ltcfoutpu
tgt lta href Index.cfm?Fuseactionnameformreque
st.urltokengtAdd Namelt/agtltpgt lt/cfoutputgt ltcfoutpu
t queryGetNamesgt first_name
last_nameltBRgt lt/cfoutputgt lt/bodygt lt/htmlgt
30Example Code 2 dsp_nameform.cfm
lt!---dsp_nameform.cfm---gt lthtmlgt ltbodygt ltcfoutput
gt ltform methodpost actionindex.cfm?request.urlt
okengt ltinput type hidden name
fuseaction valueaddnamegt First Name
ltinput name first_name maxlength30gtltBRgt Last
Name ltinput name Last_name
maxlength30gtltBRgt ltBRgt ltinput type submit
ValueSavegt lt/formgt lt/cfoutputgt lt/bodygt lt/htmlgt
31Example Code 2 act_addname.cfm
lt!---act_addname.cfm---gt ltcfquery nameaddName
datasourcerequest.maindsngt insert
into Users(first_name,last_name)
values(attributes.first_name,attributes.last
_name) lt/cfquerygt
32Example Code 2 URL_listnames.cfm
lt!--- url_listnames.cfm---gt ltcflocation
urlindex.cfm?request.urltoken addtokenyesgt
33Conclusion Why use Fusebox
- Fusebox is (most likely) very similar to how you
may already build an application, thus it will be
easy to learn. - It is a well thought out process, and will
continue to be improved by the CF community. - Itll save you time, which will save you money.
- Most importantly it will prevent hair loss.
34Congratulations!
- Thats all there is to Fusebox.
- Its not that scary after all.
35Fusebox Resources
- http//www.fusebox.org
- White papers and Code.
- http//www.teamAllaire.com/hal/
- Fusebox primers.
- http//www.houseoffusion.com
- Fusebox mailing list.
- http//www.fuseml.org
- Incorporating UML and Fusebox.
- http//www.secretagents.com
- Tools for Fusebox developers.