Prelude to Fusebox Prerequisite Understanding: / Variable scopes:...

20
Prelude to Fusebox Prerequisite Understanding: <cfinclude> <cflocation> <cfswitch> / <cfcase> <cfapplication> Variable scopes: session/client/application/request/attributes /caller Custom tags URLToken If you don’t understand any of these, please tell me!

Transcript of Prelude to Fusebox Prerequisite Understanding: / Variable scopes:...

Page 1: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Prelude to FuseboxPrerequisite Understanding:

<cfinclude><cflocation><cfswitch> / <cfcase><cfapplication>Variable scopes: session/client/application/request/attributes/callerCustom tagsURLToken

If you don’t understand any of these, please tell me!

Page 2: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

An Introduction to Fusebox Methodology and Techniques

Finally – A True Standard for ColdFusion’s Most Proven and Popular Application Architecture

Presented by Nat Papovich – Webthugs Consulting Developed by the Fusebox Community including Hal Helms, Jordan Clark, Steve Nelson, Fred Sanders, Jeff Peters, Russ Johnson, Ken Beard, and Stan Cox

Page 3: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Why Fusebox? What Is Fusebox?

Structured architecture - scalability, maintainability, modularityFacilitates team developmentSelf-documents your applicationAllows repeatabilityLarge community

Proven but evolvingCommunity-drivenExtensible - Fusebox for PHP, JSP, ASPQuick to learnFree

Page 4: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

General Fusebox TheoryIndex.cfm is controller - all interaction goes through the Fusebox via FuseactionsMultiple index.cfms for sections of the site, called circuitsRoot index.cfm handles global variables, root requestsIndex.cfm acts via cfcase, including files (fuses) and logicIf a circuit blows up, the entire site is not blacked outElectrical fuse box metaphorCircuits are modular, thus reusable

New Extended Fusebox (Hal-style) standard calls for no home application:

All circuits standalone with individual cfapplication tags and no global variable dependencies – cfparam all vars

All circuit index.cfms are cfincluded, not cflocationed

Page 5: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

First Steps (Pre-Coding)1. Produce a quality specification

Nothing Fusebox specific here Be on the lookout for Secretagents.com spec tool

2. Use fUseML or another modeling tool to make the design including directory structure

fUseML is derived from the UML Build design taking index.cfm interaction

(Fuseactions) into account

3. Create stringent Fusedocs for all fuses Fuses should not be dependant on any variables not

explicitly stated Make assertions if necessary

Page 6: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Creating A Fusebox Application1. Create the index.cfm files2. Create Fuseactions in index.cfm3. Create Fusedocs for fuses4. Write fuses5. Stand back and marvel

Page 7: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Create the Index.cfm FilesEvery directory (circuit application) has one index.cfm fileIndex.cfm controls all the Fuseactions of that circuit applicationIt is the FuseboxAll links and form submissions go to the index.cfmIt is a single cfswitch statement with multiple cfcase statementsEach cfcase is a different Fuseaction

Page 8: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

The Fusebox Code<!--index.cfm-->

<cf_formURL2attributes><cfinclude template=“app_globals.cfm”><cfparam name=“attributes.fuseaction” default=“login”>

<cfswitch expression=“#attributes.fuseaction#”> <cfcase value=“login”> <cfif blah> <cf_do_logic> </cfif> <cfinclude template=“dsp_UserLogin.cfm”> </cfcase> ....</cfswitch>

More on the custom tag later…

Page 9: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Model-View-Controller Approach

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

dsp_UserLogin.cfm

<a href=“index.cfm?fuseaction=login”>

Fusebox(controller)

Request

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

cf_do_logic

<!--- dsp_UserLogin.cfm ---><td>Name: Stan Cox</td><td>Intelligence: Monumental</td><td>Bravery: Stunning</td>

HTML Returned

(model)

(view)

Page 10: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Create the FuseactionsA Fuseaction may cfinclude .htm/.cfm; cfmodule; cflocation; contain limited cfmlA Fuseaction may NOT display anything to the browser or contain “open” SQL

Determine what steps are needed to complete each FuseactionAdd those steps inside each cfcase statement

<cfcase value=“MainPage”> <cfif client.IsLoggedIn> <cflocation url=“index.cfm?fuseaction=login”> <cfelse> <cfinclude template=“dsp_HomePage.cfm”></cfif></cfcase><cfcase value=“InsertRecord”> <cfinclude template=“act_InsertNewEmployee.cfm”> <cfmodule template=“conf/index.cfm?fuseaction=main&ID=7”></cfcase>

Page 11: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

File Naming Conventions (Fuses)

app_globals.cfm – File defines variables, instantiates application

request.mainDSN, request.webroot, request.mypath<cfif not IsDefined(“application.applicationname”)>

<cfapplication name=“blah”></cfif>

dsp_filename.cfm - Display file Only file that contains HTML or any output to browser

act_filename.cfm - Action file Only file allowed to perform actions on the database –

updates, inserts, deletes, selects allowed, but only in conjunction with action

qry_filename.cfm - Query file Extremely modular file can be called “willy-nilly”

throughout application, performs selects on database

Page 12: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Fusedoc Documentation Standard

A Fusedoc outlines responsibilities, customizations, and expectations of fuses, and is unique to each fuseNo fuse can assume the existence of any variable unless it is noted in the Fusedoc for that fuseOnce completed, a Fusedoc should provide all the information needed to code the fuse – no interaction with application architects or previous specifications should be neededA Fusecard contains the following elements:

Name of the file Responsibilities (non-technical, plain English, derived

from the application design/fUseML) Author / coder Variables list (incoming, outgoing, and persistent)

Page 13: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Fusedoc Legend--> explicitly passed incoming parameter<-- explicitly passed outgoing parameter<-> pass-thru parameter (unchanged)++> existing persistent parameter (session, client, etc.)<++ created persistent parameter+++ included file

[parameter] brackets indicates optional

Examples:--> CurrentUser: a WDDX STRUCTURE<-- [badLogin]: optional, a STRING<++ Session.ColorChoice: a STRING (Red|Blue)<-> UserID: an INTEGER+++ myGlobals.cfm

Page 14: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Create the Necessary FusesBecause the Fusedocs are so carefully built, and the design so thoroughly thought out, individual fuses can be “farmed out” for coding

Remember – all links and form actions go to index.cfm, specifying which Fuseaction to perform; never to the specific dsp or act files.

<a href=“index.cfm?fuseaction=startCheckout”>

Javascript:window.location=‘index.cfm?fuseaction=Buy’

<form action=“index.cfm?fuseaction=NewProduct”>or

<input type=“hidden” name=“fuseaction” value=“NewProduct”>

<cfmodule template=“index.cfm” fuseaction=“AuthorizeCard”>

<frame src=“index.cfm?fuseaction=BuildLeftFrame”>

Page 15: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Version 2: Putting It All Together

One entire application is made up of many smaller circuit applicationsOne circuit application is made up of a directory of filesEach circuit must contain an app_locals.cfm and index.cfm file plus other display/action/query files as FusesOne index.cfm file is made up of one or more FuseactionsOne Fuseaction includes one or more display/action/query files plus any necessary CFML logic

Page 16: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Extended Fusebox: Putting It All Together

Version 2 calls for multiple Fuseboxes to be tied together with cflocation or cfmoduleVersion 3 ties Fuseboxes together with cfincludes ONLYThere are no longer “circuit” and “home” apps – all index.cfms function standalone – loosely coupledAny Fusebox can cfinclude any other Fusebox without knowing or caring what variables are used or what the Fusebox’s architecture isWhen the Fuseboxes are collected, they are called from the highest Fusebox only using “dot-notation” href and form action

All hrefs and form actions call the current index.cfm which, when Fuseboxes are cfincluded, means the highest Fusebox in the chain, without having to recode links

<a href=“index.cfm?fuseaction=catalog.view&ID=3&cat=2”><a href=“catalog/index.cfm?fuseaction=view&ID=3&cat=2”>

But this Fusebox can in turn, be called by a higher Fusebox…

Page 17: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Extended Fusebox Code

<cfswitch expression=“#listfirst(attribs.fuseaction,“.”)#”> <cfcase value=“cat”> <cfset attribs.fuseaction=listRest(attribs.fuseaction,“.”)> <cfinclude template=“../dir/cat/index.cfm> </cfcase> <cfcase value=“members”> <cfset attribs.fuseaction=listRest(attribs.fuseaction,“.”)> <cfinclude template=“/apps/index.cfm”> </cfcase> <cfcase value=“Info”> <cfinclude template=“qry_ExCheck.cfm”> <cfinclude template=“dsp_FormPage.cfm”> </cfcase> </cfswitch>

Page 18: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Fusebox Glue<cf_bodycontent> / app_layout.cfm<cf_formURL2attributes>Application.cfm security<cfif ListLast(GetTemplatePath(),'\') is not

“index.cfm”>

<cflocation url="/index.cfm?fuseaction=logoff2"></cfif>

<cf_returnfuseaction>app_server.cfmSearch-engine safe URLs via modified cf_formurl2attributes<a href=“index.cfm/fuseaction/main/ID/8/cat/9.cfm”>

Verity friendly Fusebox in the works (store content in database)Exit Fuseactions (XFA)

Page 19: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Fusebox: The Final WordFusebox is nothing radical – sophisticated, large applications use the MVC approach, whether CGI, Java/J2EE, C++, PHP, ASP, etcNo one owns Fusebox – it will evolve and grow to meet any need or new technologyPlug-n-Play saves you tons of time (time=money)Other choices exist – but Fusebox is the proven solutionPurchase completed applications or cut-n-paste old code

Page 20: Prelude to Fusebox Prerequisite Understanding: / Variable scopes: session/client/application/request/attributes/caller Custom tags URLToken If you don’t.

Fusebox Resourceswww.fusebox.org - home, sites using Fuseboxwww.boxofuses.com - version 3 application sales repositorywww.houseoffusion.com - mailing listwww.halhelms.com - primers and Fusedocs

www.webthugs.com/consulting - frameswww.fuseml.org - home of fUseMLwww.secretagents.com - tutorials and toolswww.grokfusebox.com - IRC info and archiveswww.fusionauthority.com - purchase Fusebox book