<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ricardo Parente&#039;s Blog &#187; Fusebox</title>
	<atom:link href="http://ricardo.parente.us/category/frameworks/fusebox-frameworks/feed/" rel="self" type="application/rss+xml" />
	<link>http://ricardo.parente.us</link>
	<description>ColdFusion Developers Network</description>
	<lastBuildDate>Fri, 10 Feb 2012 17:13:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Fusebox 5.51 with MVC Tutorial &#8211; Part 2 New Edition</title>
		<link>http://ricardo.parente.us/2011/11/fusebox-5-51-with-mvc-tutorial-part-2-new-edition/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fusebox-5-51-with-mvc-tutorial-part-2-new-edition</link>
		<comments>http://ricardo.parente.us/2011/11/fusebox-5-51-with-mvc-tutorial-part-2-new-edition/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 01:07:30 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Fusebox]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[fusebox 5.51]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=6188</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  fopen(/7f273c45c7acd90c744dbd2d92f0a0022e5c97a2) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/5b9a203b8fc16897d6f4f37b234d72046eb44e84) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/240ec92fd15b1f7139b6afdc6b2b7425d855c363) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/e264ec6ca959d65fa484c58e874832c03dd530e7) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/edfaa846fe2455b7c50b9483845446b6edf82a88) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/b6283c0ca8cb3a09fbf3176866dac3a878b0da24) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
If you missed the part 1 of this tutorial, you may get it here. Now that we have set up the main Fusebox structure for our application, let&#8217;s continue to implement it. Layouts I want you to pay particular attention to the circuit &#8220;layout&#8221;. That circuit will not be called by any page, it is [...]]]></description>
			<content:encoded><![CDATA[<br />
<b>Warning</b>:  fopen(/7f273c45c7acd90c744dbd2d92f0a0022e5c97a2) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/5b9a203b8fc16897d6f4f37b234d72046eb44e84) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/240ec92fd15b1f7139b6afdc6b2b7425d855c363) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/e264ec6ca959d65fa484c58e874832c03dd530e7) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/edfaa846fe2455b7c50b9483845446b6edf82a88) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<br />
<b>Warning</b>:  fopen(/b6283c0ca8cb3a09fbf3176866dac3a878b0da24) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/home1/ricards2/public_html/wp-content/plugins/fv-code-highlighter/Includes/Cache.php</b> on line <b>69</b><br />
<p>If you missed the part 1 of this tutorial, you may get it <a title="Fusebox 5.51 With MVC Tutorial Part 1" href="http://ricardo.parente.us/2011/11/fusebox-5-51-with-mvc-tutorial-part-1-new-edition//" target="_self"><strong>here</strong></a>.<br />
Now that we have set up the main Fusebox structure for our application, let&#8217;s continue to implement it.</p>
<h3>Layouts</h3>
<div id="attachment_925" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-925" title="Figure 2.1" src="http://ricardo.parente.us/wp-content/uploads/2009/09/FBTutorial-04-001-300x199.jpg" alt="Figure 2.1" width="300" height="199" /><p class="wp-caption-text">Figure 2.1</p></div>
<p>I want you to pay particular attention to the circuit &#8220;layout&#8221;. That circuit will not be called by any page, it is an internal circuit, basically a &#8220;view&#8221; circuit which will assemble all the contents of the page into the layout templates we choose.</p>
<p>Now that we have our “Hello World” page working, let’s play a little with layouts. Suppose you want to have a header, content and footer as your layout (Figure 2.1). First you will have to create the contents for the header, main content and footer blocks and then insert them into the layout template. Let’s see how it is done.<br />
On the fusebox.xml.cfm template there is a tag <em>&lt;globalfuseactions&gt;</em>, followed by two tags <em>&lt;preprocess&gt;</em> and<em> &lt;postprocess&gt;</em>. Every action that you include between those tags will be processed either before or after Fusebox assembles the page.</p>
<p>We will set the header, footer and the layout actions into the<em> &lt;postprocess&gt;</em> tag, because they will be shown at the end of all Fusebox processing.<br />
<span id="more-6188"></span> The code is:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre>
<pre><span class="html"><span class="html-other-element">&lt;globalfuseactions&gt;</span>
<span class="html-other-element">&lt;preprocess&gt;</span>
<span class="html-other-element">&lt;/preprocess&gt;</span>
<span class="html-other-element">&lt;postprocess&gt;</span>
<span class="html-other-element">&lt;fuseaction action=<span class="html-attribute">&quot;vhome.header&quot;</span> contentvariable=<span class="html-attribute">&quot;content.header&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;fuseaction action=<span class="html-attribute">&quot;vhome.footer&quot;</span> contentvariable=<span class="html-attribute">&quot;content.footer&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;fuseaction action=<span class="html-attribute">&quot;layout.checkLayout&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;/postProcess&gt;</span>
<span class="html-other-element">&lt;/globalfuseaction&gt;</span></span></pre>
</div>
<p>Note, in the <em>&lt;postprocess&gt;</em> block, the attribute “contentvariable” in the fuseaction tag. That means Fusebox will process that action and will place the results into a variable instead of rendering it to the screen. Later on, we will use that variable in the layout context. We are calling actions from the “view” of the home circuit. That’s why we are calling the fuseactions <em>vhome.header</em> and <em>vhome.footer</em> before the <em>layout.checklayout</em>, because we want to load the header and footer into variables that will be used in the layout template.</p>
<p>So, let’s work now on the “layout” circuit and prepare the header, footer and default layout templates.</p>
<p>Create a ColdFusion template named dspHeader.cfm and another dspFooter.cfm inside the “home view” folder: <em>\circuits\home\vhome.</em> Add the following code to the templates:</p>
<p>dspHeader.cfm</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
</pre>
<pre><span class="html"><span class="html-other-element">&lt;cfoutput&gt;</span>
<span class="html-other-element">&lt;h2&gt;</span>#request.pageTitle#<span class="html-other-element">&lt;/h2&gt;</span>
<span class="html-other-element">&lt;hr/&gt;</span>
<span class="html-other-element">&lt;/cfoutput&gt;</span></span></pre>
</div>
<p>dspFooter.cfm</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
</pre>
<pre>&lt;hr/&gt;
&lt;h4&gt;&copy;2009 Your Name&lt;/h4&gt;</pre>
</div>
<p>Now, let&#8217;s edit the <em>circuit.xml.cfm</em> template in the &#8220;vhome&#8221; circuit:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre>
<pre><span class="html"><span class="html-other-element">&lt;!DOCTYPE circuit&gt;</span>
<span class="html-other-element">&lt;? xml version=<span class="html-attribute">&quot;1.0&quot;</span> encoding=<span class="html-attribute">&quot;UTF-8&quot;</span>?&gt;</span>
<span class="html-comment">&lt;!-- vhome --&gt;</span>
<span class="html-other-element">&lt;circuit access=<span class="html-attribute">&quot;internal&quot;</span> xmlns:cf=<span class="html-attribute">&quot;cf/&quot;</span>&gt;</span>
<span class="html-other-element">&lt;fuseaction name=<span class="html-attribute">&quot;main&quot;</span>&gt;</span>
<span class="html-other-element">&lt;set name=”request.pageTitle” value=”Fusebox Tutorial” overwrite=”true” /&gt;</span>
<span class="html-other-element">&lt;include template=<span class="html-attribute">&quot;dspMain&quot;</span> required=<span class="html-attribute">&quot;true&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;/fuseaction&gt;</span>
<span class="html-other-element">&lt;fuseaction name=<span class="html-attribute">&quot;header&quot;</span>&gt;</span>
<span class="html-other-element">&lt;include template=<span class="html-attribute">&quot;dspHeader&quot;</span> required=<span class="html-attribute">&quot;true&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;/fuseaction&gt;</span>
<span class="html-other-element">&lt;fuseaction name=<span class="html-attribute">&quot;footer&quot;</span>&gt;</span>
<span class="html-other-element">&lt;include template=<span class="html-attribute">&quot;dspFooter&quot;</span> required=<span class="html-attribute">&quot;true&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;/fuseaction&gt;</span>
<span class="html-other-element">&lt;/circuit&gt;</span></span></pre>
</div>
<p>With that, we accomplished the Header and Footer to be included in our layout. Notice the setting of the variable <em>request.pageTitle</em> with an attribute of <em>overwrite=’true’</em>; that will be used in the header when included into the layout template. Now, let’s look at the layout itself.</p>
<p>You noticed the call to the layout fuseaction in the fusebox.xml.cfm under the tag <em>&lt;postprocess&gt;</em> in the global fuseactions section:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
</pre>
<pre><span class="html"><span class="html-other-element">&lt;postprocess&gt;</span>
<span class="html-other-element">&lt;fuseaction action=<span class="html-attribute">&quot;layout.checkLayout&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;/postProcess&gt;</span></span></pre>
</div>
<p>That fuseaction will call the “checkLayout” fuse in the circuit “layout”, and it will check if we want to use a layout or which layout template to load.<br />
So, let’s write that “checkLayout” in <em>\circuits\layout\circuit.xml.cfm</em>:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre>
<pre><span class="html"><span class="html-other-element">&lt;? xml version=<span class="html-attribute">&quot;1.0&quot;</span> encoding=<span class="html-attribute">&quot;UTF-8&quot;</span>?&gt;</span>
<span class="html-other-element">&lt;!DOCTYPE circuit&gt;</span>
<span class="html-comment">&lt;!-- circuit: LAYOUT --&gt;</span>
<span class="html-other-element">&lt;circuit access=<span class="html-attribute">&quot;internal&quot;</span> xmlns:cf=<span class="html-attribute">&quot;cf/&quot;</span>&gt;</span>
<span class="html-other-element">&lt;fuseaction name=<span class="html-attribute">&quot;checkLayout&quot;</span>&gt;</span>
<span class="html-other-element">&lt;set name=<span class="html-attribute">&quot;request.useLayout&quot;</span> value=<span class="html-attribute">&quot;default&quot;</span> overwrite=<span class="html-attribute">&quot;false&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;if condition=<span class="html-attribute">&quot;request.useLayout is 'default'&quot;</span>&gt;</span>
<span class="html-table-element">&lt;true&gt;</span>
<span class="html-other-element">&lt;include template=<span class="html-attribute">&quot;layDefault&quot;</span> required=<span class="html-attribute">&quot;true&quot;</span> /&gt;</span>
<span class="html-table-element">&lt;/true&gt;</span>
<span class="html-other-element">&lt;/if&gt;</span>
<span class="html-other-element">&lt;if condition=<span class="html-attribute">&quot;request.useLayout is 'brochure'&quot;</span>&gt;</span>
<span class="html-table-element">&lt;true&gt;</span>
<span class="html-other-element">&lt;include template=<span class="html-attribute">&quot;layBrochure&quot;</span> required=<span class="html-attribute">&quot;true&quot;</span> /&gt;</span>
<span class="html-table-element">&lt;/true&gt;</span>
<span class="html-other-element">&lt;/if&gt;</span>
<span class="html-other-element">&lt;/fuseaction&gt;</span>
<span class="html-other-element">&lt;/circuit&gt;</span></span></pre>
</div>
<p>First we set a default value for the variable <em>“request.useLayout” </em>with the attribute <em>“overwrite”</em> to <em>“false”</em> because we don’t want overwrite it in case it already exists.</p>
<p>Then we start checking for its value, if it is “default”, include the default template, if it is “brochure” then include the brochure layout template, and so on (you may have as many layouts you want).</p>
<p>Have you noticed that you do not need to write the file extension .cfm for the template names in the<em> &lt;include&gt;</em> tag? Fusebox will assume you are loading ColdFusion templates if you do not specify the file extension.</p>
<p>Now that we have the header, footer and layout calls, let’s work on the default layout template in <em>\circuits\layout\layDefault.cfm</em>:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre>
<pre><span class="html"><span class="html-other-element">&lt;cfparam name=<span class="html-attribute">&quot;content.header&quot;</span> default=<span class="html-attribute">&quot;This is the Header&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;cfparam name=<span class="html-attribute">&quot;content.footer&quot;</span> default=<span class="html-attribute">&quot;This is the Footer&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;cfparam name=<span class="html-attribute">&quot;content.mainContent&quot;</span> default=<span class="html-attribute">&quot;This is the main content&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;cfparam name=<span class="html-attribute">&quot;request.pageTitle&quot;</span> default=<span class="html-attribute">&quot;FPTutorial&quot;</span> /&gt;</span>
<span class="html-other-element">&lt;html&gt;</span>
<span class="html-other-element">&lt;head&gt;</span>
<span class="html-other-element">&lt;cfoutput&gt;</span><span class="html-other-element">&lt;title&gt;</span>#request.pageTitle#<span class="html-other-element">&lt;/title&gt;</span><span class="html-other-element">&lt;/cfoutput&gt;</span>
<span class="html-other-element">&lt;/head&gt;</span>
<span class="html-other-element">&lt;body&gt;</span>
<span class="html-other-element">&lt;cfoutput&gt;</span>
<span class="html-other-element">&lt;p&gt;</span>#content.header#<span class="html-other-element">&lt;/p&gt;</span>
<span class="html-other-element">&lt;p&gt;</span>#content.mainContent#<span class="html-other-element">&lt;/p&gt;</span>
<span class="html-other-element">&lt;p&gt;</span>#content.footer#<span class="html-other-element">&lt;/p&gt;</span>
<span class="html-other-element">&lt;/cfoutput&gt;</span>
<span class="html-other-element">&lt;/body&gt;</span>
<span class="html-other-element">&lt;/html&gt;</span></span></pre>
</div>
<p>Run your application and you should receive a page like Figure 2.2.</p>
<div id="attachment_929" class="wp-caption alignright" style="width: 241px"><img class="size-full wp-image-929" title="FBTutorial-02-002" src="http://ricardo.parente.us/wp-content/uploads/2009/09/FBTutorial-02-002.jpg" alt="Figure 2.2" width="231" height="195" /><p class="wp-caption-text">Figure 2.2</p></div>
<p>On the next part of this tutorial we will work with some content for the main page, to replace the &#8220;Hello World&#8221;.</p>
<p>The idea is to make you comfortable with the framework showing where to add fuses, variables, include templates, etc.</p>
<p>Just keep in mind that if you are using layouts, you must create all your content, save it to variables before Fusebox finishes processing and throwing the layout page.</p>
<p>Thank you for your interest and feel free to write any comment to this post.</p>
<p><a title="Download Files for this Tutorial" href="http://ricardo.parente.us/wp-content/uploads/2009/09/FBTutorial.zip" target="_blank"><strong>Download here</strong></a> the zip file with the files for this tutorial. Please note that the fusebox.xml.cfm contain commented circuits for future development.</p>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2011/11/fusebox-5-51-with-mvc-tutorial-part-2-new-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fusebox 5.51 with MVC Tutorial &#8211; Part 1 New Edition</title>
		<link>http://ricardo.parente.us/2011/11/fusebox-5-51-with-mvc-tutorial-part-1-new-edition/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fusebox-5-51-with-mvc-tutorial-part-1-new-edition</link>
		<comments>http://ricardo.parente.us/2011/11/fusebox-5-51-with-mvc-tutorial-part-1-new-edition/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 01:01:42 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Fusebox]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[fusebox 5.51]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=6185</guid>
		<description><![CDATA[Unfortunately something happened to my old tutorial when I switched Internet provider and the posts were messed up, I got some complains, so I&#8217;m re-posting them here. This is Part 1: I work with Fusebox framework since its version 2. Now we are at version 5.51. I decided to write this tutorial to help some [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunately something happened to my old tutorial when I switched Internet provider and the posts were messed up, I got some complains, so I&#8217;m re-posting them here.<br />
This is Part 1:</p>
<p>I work with Fusebox framework since its version 2. Now we are at version 5.51. I decided to write this tutorial to help some friends who haven&#8217;t got into Fusebox yet but are anxious to jump into the bandwagon, just don&#8217;t know how to start. I recommend Jeff Peter’s books on Fusebox for those who really want to take advantage of this framework:</p>
<ul>
<li><a title="Fusebox 5 &amp; Flip Master Class" href="http://www.cafepress.com/protonarts.126485280" target="_blank"><strong>Fusebox 5 &amp; Flip Master-Class ColdFusion Applications</strong></a></li>
<li><a title="How to Drive Fusebox 5.5" href="http://www.cafepress.com/protonarts.297794563" target="_blank"><strong> How to Drive Fusebox 5.5 </strong></a></li>
</ul>
<p><span id="more-6185"></span></p>
<h3>MVC &#8211; Model View Controller</h3>
<p>Before going into the framework, let&#8217;s talk a little about MVC (Model, View, Controller). For those who don&#8217;t know MVC, it is a method of separating the presentation, action and control layers of the application in order to achieve better and secure way of programming, and easier maintenance.</p>
<p>All external calls (from the web URL) are directed to the Control layer. Then the Control will decide which actions to take, like performing a query, a calculation, etc&#8230; That is done in the Model layer, which has no access from the outside world. Then the Control will submit the results to the View (presentation layer) which will assemble the contents to the public. Basically, all public link addresses to your website will be calling the Control layer. All your queries and action pages will be in the Model, and all your display pages will be in the View, easy to find and maintain.</p>
<p>Example: if you have to show a list of real estate properties, the Control will call a query in the Model to obtain the data and then call a display page in the View to show all the properties selected in the query.</p>
<h3>Fusebox</h3>
<div id="attachment_781" class="wp-caption alignright" style="width: 112px"><img class="size-medium wp-image-781 " title="FBTutorial-01-000" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-000-127x300.jpg" alt="Figure 1.1" width="102" height="240" /><p class="wp-caption-text">Figure 1.1</p></div>
<p>Fusebox is a methodology for developing web applications. It protects your application by forcing all calls to be made to a single template: index.cfm, which acts as the hub where all connections are made. By passing the &#8220;fuseaction&#8221; attribute, you will tell the Fusebox framework what action you want to be executed.</p>
<p>So, with the analogy to the &#8220;electric fusebox&#8221;, the framework is divided into &#8220;circuits&#8221; and &#8220;fuses&#8221;. Your application folders are called &#8220;circuits&#8221; and the ColdFusion templates are the &#8220;fuses&#8221;.</p>
<p>In this tutorial we will be referencing the Fusebox 5.51 XML version, not the non-xml one (sort of OO). Let&#8217;s start by downloading the <a title="Fusebox 5.51 Core Files" href="http://fusebox.org/go/fusebox-downloads/core-files" target="_blank"><strong>Fusebox 5.51 Core Files</strong></a>, select the first link: Official FB5.5.1/CFMX core files (v5.5.1).</p>
<p>Unzip the contents to a folder named &#8220;fusebox5&#8243; inside your web application root if you <strong>DO NOT</strong> have access to the ColdFusion administration site. Otherwise, extract the contents to a folder outside your web root and then map it as &#8220;/fusebox5&#8243;. Doing that, you will be able to have multiple websites using the same Fusebox core installation.</p>
<p>Your Fusebox core structure should be like <em>Figure 1.1</em> side.</p>
<div id="attachment_785" class="wp-caption alignright" style="width: 234px"><img class="size-full wp-image-785" title="FBTutorial-01-003" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-003.jpg" alt="Figure 1.2" width="224" height="82" /><p class="wp-caption-text">Figure 1.2</p></div>
<p>We are going to create a web application for a store called FBTutorial. Here are the initial application requirements:</p>
<ul>
<li>Home Page with News Articles</li>
<li>Contact Page &#8211; form</li>
<li>Products page &#8211; catalog</li>
<li>Shopping Cart</li>
</ul>
<div id="attachment_783" class="wp-caption alignright" style="width: 108px"><img class="size-medium wp-image-783 " title="FBTutorial-01-001b" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-001b-122x300.jpg" alt="Figure 1.3" width="98" height="240" /><p class="wp-caption-text">Figure 1.3</p></div>
<p>I know two ways of creating the MVC structure for a Fusebox application. One is most used by creating 3 folders: <em>_model</em>,<em> _view</em> and <em>_controller</em> (the underscores are for placing the folders on top of the other regular ones), and inside those folders we would put the Fusebox circuits.</p>
<p>I find that more complicated and less modular. Any maintenance you need to do, you will have to look at the subfolders inside other subfolders, etc&#8230; (<em>figure 1.3</em>)</p>
<p>If you want to turn a circuit into a module that could be copied to other application, the better approach should be creating the circuits first, and then inside each circuit you create the folders &#8220;model&#8221; and &#8220;view&#8221;, being the circuit root itself working as the &#8220;controller&#8221;.</p>
<p>So I chose the second structure by creating the circuit folders and</p>
<div id="attachment_782" class="wp-caption alignright" style="width: 120px"><img class="size-full wp-image-782 " title="FBTutorial-01-001" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-001.jpg" alt="Figure 1.4" width="110" height="153" /><p class="wp-caption-text">Figure 1.4</p></div>
<p>then their subfolders model and view (<em>Figure 1.4</em>). Here is how we will create the application structure:</p>
<ul>
<li>FBTutorial
<ul>
<li>circuits
<ul>
<li>forms</li>
<li>home</li>
<li>news</li>
<li>products</li>
<li>shopping</li>
</ul>
</li>
<li>other folders&#8230;</li>
</ul>
</li>
</ul>
<p>Now, inside each circuit folder, we will create the folders &#8220;<em>model</em>&#8221; and &#8220;<em>view</em>&#8220;. You decide</p>
<div id="attachment_786" class="wp-caption alignright" style="width: 132px"><img class="size-full wp-image-786 " title="FBTutorial-01-004" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-004.jpg" alt="Figure 1.5" width="122" height="145" /><p class="wp-caption-text">Figure 1.5</p></div>
<p>if you want to prefix them with underscore &#8220;_&#8221;, since you will not have any other folder in the circuits.</p>
<p>After creating all the necessary folders, we need to create empty control files in each folder. Those files will be named &#8220;circuit.xml.cfm&#8221;, which are XML files but with the extention CFM so they cannot be read by the browser without being parsed by ColdFusion. Just create the empty files for now.</p>
<p><em>Figure 1.5</em> shows the new structure with the XML files.</p>
<p>Do not worry about the empty files, we will fill them in later.</p>
<div id="attachment_788" class="wp-caption alignright" style="width: 140px"><img class="size-full wp-image-788 " title="FBTutorial-01-005" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-005.jpg" alt="Figure 1.6" width="130" height="96" /><p class="wp-caption-text">Figure 1.6</p></div>
<p>I&#8217;m just preparing the application structure before starting coding.</p>
<p>Now, let&#8217;s create the Fusebox required and optional files on the application root. Starting with the <em>Application.cfc</em> (capital &#8220;A&#8221;),<em> fusebox.appinit.cfm</em>, <em>fusebox.init.cfm</em>, f<em>usebox.xml.cfm</em> and <em>index.cfm</em> (create those empty files and we&#8217;ll work on them next. Your structure now should be like <em>Figure 1.6.</em></p>
<h3>Application Root</h3>
<p>Let&#8217;s start now working on the Fusebox files on the application root. First of all, the <em>Application.cfc</em> component which is always the first to run on each request.<br />
The basic methods in the Application.cfc component are:</p>
<ul>
<li>onApplicationStart,</li>
<li>onApplicationEnd,</li>
<li>onSessionStart,</li>
<li>onSessionEnd,</li>
<li>onRequestStart</li>
</ul>
<p>You may have additional methods like onRequestEnd, onError&#8230; but right now we are interested in the Fusebox method:<strong> onFuseboxApplicationStart</strong>. That method is called when the Fusebox application initiates. It replaces the template <em>fusebox.appinit.cfm</em> in the application root. So if you may decide to use this method instead of that template, then it’s one less file to maintain.</p>
<p>Here is our <em>Application.cfc</em> template:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
</pre>
<pre>&lt;cfcomponent extends=&quot;fusebox5.Application&quot; output=&quot;false&quot;&gt;
&lt;cfscript&gt;
this.name = right(REReplace(expandPath(&#039;.&#039;),&#039;[^A-Za-z]&#039;,&#039;&#039;,&#039;all&#039;),64);
this.applicationTimeout = createTimeSpan(0,6,0,0);
this.sessionManagement = true;
this.sessionTimeout = createTimeSpan(0,0,30,0);
this.clientManagement = true;
this.mainDSN = &quot;myDSN&quot;;
this.webmasterEmail = &quot;myEmail@myDomain.com&quot;;
&lt;/cfscript&gt;
&lt;!--- trap non-index.cfm requests - must be outside onXxxYyy() handlers ---&gt;
&lt;cfif right(cgi.script_name, len(&quot;index.cfm&quot;)) neq &quot;index.cfm&quot; and
right(cgi.script_name, 3) neq &quot;cfc&quot;&gt;
&lt;cflocation url=&quot;index.cfm&quot; addtoken=&quot;no&quot; /&gt;
&lt;/cfif&gt;
&lt;cffunction name=&quot;onApplicationStart&quot; returntype=&quot;boolean&quot; output=&quot;false&quot;&gt;
&lt;cfreturn True&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onApplicationEnd&quot; output=&quot;false&quot;&gt;
&lt;cfargument name=&quot;applicationScope&quot; required=&quot;true&quot; /&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onSessionStart&quot; output=&quot;false&quot;&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onSessionEnd&quot; output=&quot;false&quot;&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onFuseboxApplicationStart&quot;&gt;
&lt;cfset super.onFuseboxApplicationStart() /&gt;
&lt;!--- code formerly in fusebox.appinit.cfm ---&gt;
&lt;cfif not structKeyExists(application,&quot;mainDSN&quot;)&gt;
&lt;cflock name=&quot;mainDSN&quot; type=&quot;exclusive&quot; timeout=&quot;10&quot;&gt;
&lt;cfset application.mainDSN = this.mainDSN /&gt;
&lt;/cflock&gt;
&lt;/cfif&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onRequestStart&quot;&gt;
&lt;cfargument name=&quot;targetPage&quot; /&gt;
&lt;cfscript&gt;
super.onRequestStart(arguments.targetPage);
//code formerly in fusebox.init.cfm
self = myFusebox.getSelf();
myself = myFusebox.getMyself();
if (listFirst(CGI.SERVER_NAME, &quot;.&quot;) == &quot;www&quot;) {
FUSEBOX_PARAMETERS.mode = &quot;production&quot; ;
} else {
FUSEBOX_PARAMETERS.mode = &quot;development-circuit-load&quot; ;
}
// request scope
request.applicationName = this.name;
request.mainDSN = this.mainDSN;
request.webmasterEmail = this.webmasterEmail;
request.baseDir = GetDirectoryFromPath(GetBaseTemplatePath());
request.componentPath = &quot;assets.components.&quot;;
request.imagePath = &quot;assets/images/&quot;;
request.cssPath = &quot;assets/css/&quot;;
request.jsPath = &quot;assets/js/&quot;;
request.flashPath = &quot;assets/multimedia/&quot;;
request.videoPath = &quot;assets/multimedia/&quot;;
request.ppsPath = &quot;assets/multimedia/&quot;;
&lt;/cfscript&gt;
&lt;/cffunction&gt;
&lt;/cfcomponent&gt;</pre>
</div>
<p>Now, here is the deal. Since the Fusebox core also has an Application.cfc with the same methods, we need to extend our Application.cfc to the Fusebox one and make use of the &#8220;call super&#8221; to invoke those methods first in order to use ours. On the first line, we extend the component. Remember to map /fusebox5 in your ColdFusion adminstration to the folder were you saved the core files.</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
</pre>
<pre>&lt;cfcomponent extends=&quot;fusebox5.Application&quot; output=&quot;false&quot;&gt;</pre>
</div>
<p>The method onFuseboxApplicationStart must have the call super:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
</pre>
<pre>&lt;cffunction name=&quot;onFuseboxApplicationStart&quot;&gt;
&lt;cfset super.onFuseboxApplicationStart() /&gt;
… … …</pre>
</div>
<p>onRequestStart should have also the call super:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
</pre>
<pre>&lt;cffunction name=&quot;onRequestStart&quot;&gt;
&lt;cfargument name=&quot;targetPage&quot; /&gt;
&lt;cfscript&gt;
super.onRequestStart(arguments.targetPage);
… … …</pre>
</div>
<p>Some code that was formerly in fusebox.init.cfm:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
</pre>
<pre>self = myFusebox.getSelf();
myself = myFusebox.getMyself();
if (listFirst(CGI.SERVER_NAME, &quot;.&quot;) == &quot;www&quot;) {
FUSEBOX_PARAMETERS.mode = &quot;production&quot; ;
} else {
FUSEBOX_PARAMETERS.mode = &quot;development-circuit-load&quot; ;
}</pre>
</div>
<h4>Fusebox.init.cfm</h4>
<p>We basically wrote all the necessary code for starting with the Application.cfc, now let&#8217;s concentrate on the Fusebox template fusebox.init.cfm. It is included by the framework at the start of every request. It is included within a cfsilent tag so it cannot generate output. It is intended to be for per-request initialization and manipulation of the fuseaction variables.</p>
<p>You can set attributes.fuseaction, for example, to override the default fuseaction. Fusebox 5.1 and later &#8211; set variables implicitly from the Fusebox itself.</p>
<p>Could also modify the self location here:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
</pre>
<pre>&lt;cfset myFusebox.setSelf(&quot;/myapp/start.cfm&quot;) /&gt;</pre>
</div>
<p>For now, just write the following code in your fusebox.init.cfm template:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
</pre>
<pre>&lt;cfprocessingdirective suppresswhitespace=&quot;true&quot;&gt;
&lt;!--- some future code here ---&gt;
&lt;/cfprocessingdirective&gt;</pre>
</div>
<h4>Index.cfm</h4>
<p>The index.cfm template will have only one statement:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
</pre>
<pre>&lt;cfinclude template=&quot;/fusebox5/fusebox5.cfm&quot; /&gt;</pre>
</div>
<p>In a Fusebox application the index.cfm template has no use other than to include the framework.</p>
<h4>Fusebox.xml.cfm</h4>
<p>The last file on the application root we have to work on is the fusebox.xml.cfm, which is the file that controls all the fusebox circuits, parameters, classes, plugins and global actions.<br />
In the &#8220;circuits” block we define the paths and aliases for the circuits. You may chose any name as an alias to a circuit, does not have to be the same name of the folder, you will see below that we are calling “cart” the circuit in the folder “shopping”.<br />
The “parameters” block contains Fusebox default settings, and it is customizable.<br />
Here is our fusebox.xml.cfm file:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
</pre>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE fusebox&gt;
&lt;!--Example fusebox.xml control file. Shows how to define circuits, classes, parameters and global fuseactions. This is just a test namespace for the plugin custom attribute example --&gt;
&lt;fusebox xmlns:test=&quot;test&quot;&gt;
&lt;circuits&gt;
&lt;!-- Home circuit --&gt;
&lt;circuit alias=&quot;home&quot; path=&quot;circuits/home/&quot; parent=&quot;&quot; /&gt;
&lt;circuit alias=&quot;mhome&quot; path=&quot;circuits/home/model/&quot; parent=&quot;home&quot; /&gt;
&lt;circuit alias=&quot;vhome&quot; path=&quot;circuits/home/view/&quot; parent=&quot;home&quot; /&gt;
&lt;!-- Forms circuit --&gt;
&lt;circuit alias=&quot;forms&quot; path=&quot;circuits/forms/&quot; parent=&quot;home&quot; /&gt;
&lt;circuit alias=&quot;mforms&quot; path=&quot;circuits/forms/model/&quot; parent=&quot;forms&quot; /&gt;
&lt;circuit alias=&quot;vforms&quot; path=&quot;circuits/forms/view/&quot; parent=&quot;forms&quot; /&gt;
&lt;!-- News circuit --&gt;
&lt;circuit alias=&quot;news&quot; path=&quot;circuits/news/&quot; parent=&quot;home&quot; /&gt;
&lt;circuit alias=&quot;mnews&quot; path=&quot;circuits/news/model/&quot; parent=&quot;news&quot; /&gt;
&lt;circuit alias=&quot;vnews&quot; path=&quot;circuits/news/view/&quot; parent=&quot;news&quot; /&gt;
&lt;!-- Products circuit --&gt;
&lt;circuit alias=&quot;products&quot; path=&quot;circuits/products/&quot; parent=&quot;home&quot;/&gt;
&lt;circuit alias=&quot;mproducts&quot; path=&quot;circuits/products/model/&quot; parent=&quot;products&quot; /&gt;
&lt;circuit alias=&quot;vproducts&quot; path=&quot;circuits/products/view/&quot; parent=&quot;products&quot; /&gt;
&lt;!-- shopping circuit --&gt;
&lt;circuit alias=&quot;cart&quot; path=&quot;circuits/shopping/&quot; parent=&quot;home&quot; /&gt;
&lt;circuit alias=&quot;mcart&quot; path=&quot;circuits/shopping/model/&quot; parent=&quot;cart&quot; /&gt;
&lt;circuit alias=&quot;vcart&quot; path=&quot;circuits/shopping/view/&quot; parent=&quot;cart&quot; /&gt;
&lt;!-- Layout circuit --&gt;
&lt;circuit alias=&quot;layout&quot; path=&quot;circuits/layout/&quot; /&gt;
&lt;/circuits&gt;
&lt;classes&gt;
&lt;/classes&gt;
&lt;parameters&gt;
&lt;parameter name=&quot;defaultFuseaction&quot; value=&quot;home.main&quot; /&gt;
&lt;!-- you may want to change this to development-full-load mode: --&gt;
&lt;parameter name=&quot;mode&quot; value=&quot;development-full-load&quot; /&gt;
&lt;!-- change this to something more secure: --&gt;
&lt;parameter name=&quot;password&quot; value=&quot;&quot; /&gt;
&lt;parameter name=&quot;strictMode&quot; value=&quot;true&quot; /&gt;
&lt;!-- These are all default values that can be overridden:
&lt;parameter name=&quot;fuseactionVariable&quot; value=&quot;fuseaction&quot; /&gt;
&lt;parameter name=&quot;precedenceFormOrUrl&quot; value=&quot;form&quot; /&gt;
&lt;parameter name=&quot;scriptFileDelimiter&quot; value=&quot;cfm&quot; /&gt;
&lt;parameter name=&quot;maskedFileDelimiters&quot; value=&quot;htm,cfm,cfml,php,php4,asp,aspx&quot; /&gt;
&lt;parameter name=&quot;characterEncoding&quot; value=&quot;utf-8&quot; /&gt;
&lt;paramater name=&quot;strictMode&quot; value=&quot;false&quot; /&gt;
&lt;parameter name=&quot;allowImplicitCircuits&quot; value=&quot;false&quot; /&gt;
&lt;parameter name=&quot;debug&quot; value=&quot;false&quot; /&gt; --&gt;
&lt;/parameters&gt;
&lt;globalfuseactions&gt;
&lt;preprocess&gt;
&lt;/preprocess&gt;
&lt;postprocess&gt;
&lt;/postprocess&gt;
&lt;/globalfuseactions&gt;
&lt;plugins&gt;
&lt;phase name=&quot;preProcess&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;preFuseaction&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;postFuseaction&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;fuseactionException&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;postProcess&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;processError&quot;&gt;
&lt;/phase&gt;
&lt;/plugins&gt;
&lt;/fusebox&gt;</pre>
</div>
<p>We define the circuits in the &#8220;circuits&#8221; block by assigning an alias to the path. In the application we will call the index.cfm passing the circuit,fuse and fuseaction we want to execute. Example:</p>
<div id="attachment_867" class="wp-caption alignright" style="width: 152px"><img class="size-full wp-image-867 " title="FBTutorial-01-007" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-007.jpg" alt="Figure 1.7" width="142" height="90" /><p class="wp-caption-text">Figure 1.7</p></div>
<p>index.cfm?fuseaction=home.main<br />
index.cfm?fuseaction=products.showProduct&amp;productID=1234<br />
index.cfm?fuseaction=cart.addToCart</p>
<p>With Fusebox, everything is assembled in the root. The index.cfm loads Fusebox and it prepares the request to be served without the customer seeing in which folders the templates are.<br />
We added a circuit named &#8220;layout&#8221; which will handle all the layouts for our application. Since it is for the presentation layer, we do not have to create the &#8220;model&#8221; folder. <em>Figure 1.7</em> shows an updated version of our structure.</p>
<h4>Circuit.xml.cfm</h4>
<p>Now we are going to look at the<em> circuit.xml.cfm</em> file placed in all circuits.<br />
Let&#8217;s start with the &#8220;home&#8221; main circuit, the controller one&#8221; <em>/circuits/home/circuit.xml.cfm:</em><br />
For now we will not have any actions to call, just a display page to show the homepage, then our circuit.xml.cfm file will have the following code:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
</pre>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!-- home --&gt;
&lt;circuit access=&quot;public&quot; xmlns:cf=&quot;cf/&quot;&gt;
&lt;fuseaction name=&quot;main&quot;&gt;
&lt;do action=&quot;vhome.main&quot; /&gt;
&lt;/fuseaction&gt;
&lt;/circuit&gt;</pre>
</div>
<p>You noticed that we here we are calling an action on another circuit, the &#8220;vhome&#8221;, in the &#8220;view&#8221; part of the MVC, to display the homepage. If we had to calculate anything or grab any information from a database in order to populate that homepage, then we would call the &#8220;model&#8221; layer before the &#8220;view&#8221;.</p>
<p>The call to &#8220;index.cfm?fuseaction=home.main&#8221; will get to this circuit which will call the &#8220;vhome.main&#8221; fuseaction in the &#8220;view&#8221; area. Subsequently that fuseaction, &#8220;vhome.main&#8221;, will include the template &#8220;dspMain.cfm&#8221; with the contents of the homepage, and then Fusebox will assemble the full page for ColdFusion to render to the browser. Note that the attribute “access” for this circuit is set to “public”. That means it can be accessed by the web browser, it is a public fuse.</p>
<p>Here is the circuit.xml.cfm file in the &#8220;view&#8221; area:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE circuit&gt;
&lt;!-- vhome --&gt;
&lt;circuit access=&quot;internal&quot; xmlns:cf=&quot;cf/&quot;&gt;
&lt;fuseaction name=&quot;main&quot;&gt;
&lt;include template=&quot;dspMain.cfm&quot; required=&quot;true&quot; /&gt;
&lt;/fuseaction&gt;
&lt;/circuit&gt;</pre>
</div>
<p>In this case, the “access” attribute is set to “internal” which means this circuit can be only called by another circuit, it will not respond to browser calls.</p>
<p>The fuseaction “main” will include the template dspMain.cfm.<br />
Just for testing purpose, create the file dspMain.cfm with the following HTML code:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
</pre>
<pre>&lt;h1&gt;Hello World&lt;/h1&gt;</pre>
</div>
<p>Now, let&#8217;s test the site. If you have ColdFusion Developer Edition installed in your machine, just browse to: &#8220;<em>http://localhost/FBtutorial</em>&#8220;. You do not have to specify any attributes, because the Fusebox configuration file (fusebox.xml.cfm) will take care of calling the default fuseaction &#8220;home.main&#8221;.<br />
You should get the page <strong>&#8220;Hellow World&#8221;</strong>.</p>
<p>On the next part we will start handling layouts.</p>
<p>I hope you have liked this tutorial and please feel free to comment if you have questions.</p>
<p><a title="Fusebox 5.51 with MVC Tutorial Part 2" href="http://ricardo.parente.us/2009/09/fusebox-5-51-with-mvc-tutorial-part-2/" target="_self"><strong>Part 2</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2011/11/fusebox-5-51-with-mvc-tutorial-part-1-new-edition/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Fusebox 5.51 With MVC Tutorial Part 1</title>
		<link>http://ricardo.parente.us/2009/08/fusebox-5-51-with-mvc-tutorial-part-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fusebox-5-51-with-mvc-tutorial-part-1</link>
		<comments>http://ricardo.parente.us/2009/08/fusebox-5-51-with-mvc-tutorial-part-1/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 02:58:46 +0000</pubDate>
		<dc:creator>rparente</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Fusebox]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://ricardo.parente.us/?p=763</guid>
		<description><![CDATA[I work with Fusebox framework since its version 2. Now we are at version 5.51. I decided to write this tutorial to help some friends who haven&#8217;t got into Fusebox yet but are anxious to jump into the bandwagon, just don&#8217;t know how to start. I recommend Jeff Peter’s books on Fusebox for those who [...]]]></description>
			<content:encoded><![CDATA[<p>I work with Fusebox framework since its version 2. Now we are at version 5.51. I decided to write this tutorial to help some friends who haven&#8217;t got into Fusebox yet but are anxious to jump into the bandwagon, just don&#8217;t know how to start. I recommend Jeff Peter’s books on Fusebox for those who really want to take advantage of this framework:</p>
<ul>
<li> <a title="Fusebox 5 &amp; Flip Master Class" href="http://www.cafepress.com/protonarts.126485280" target="_blank"><strong>Fusebox 5 &amp; Flip Master-Class ColdFusion Applications</strong></a></li>
<li><a title="How to Drive Fusebox 5.5" href="http://www.cafepress.com/protonarts.297794563" target="_blank"><strong> How to Drive Fusebox 5.5 </strong></a></li>
</ul>
<p><span id="more-763"></span></p>
<h3>MVC &#8211; Model View Controller</h3>
<p>Before going into the framework, let&#8217;s talk a little about MVC (Model, View, Controller). For those who don&#8217;t know MVC, it is a method of separating the presentation, action and control layers of the application in order to achieve better and secure way of programming, and easier maintenance.</p>
<p>All external calls (from the web URL) are directed to the Control layer. Then the Control will decide which actions to take, like performing a query, a calculation, etc&#8230; That is done in the Model layer, which has no access from the outside world. Then the Control will submit the results to the View (presentation layer) which will assemble the contents to the public. Basically, all public link addresses to your website will be calling the Control layer. All your queries and action pages will be in the Model, and all your display pages will be in the View, easy to find and maintain.</p>
<p>Example: if you have to show a list of real estate properties, the Control will call a query in the Model to obtain the data and then call a display page in the View to show all the properties selected in the query.</p>
<h3>Fusebox</h3>
<div id="attachment_781" class="wp-caption alignright" style="width: 112px"><img class="size-medium wp-image-781 " title="FBTutorial-01-000" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-000-127x300.jpg" alt="Figure 1.1" width="102" height="240" /><p class="wp-caption-text">Figure 1.1</p></div>
<p>Fusebox is a methodology for developing web applications. It protects your application by forcing all calls to be made to a single template: index.cfm, which acts as the hub where all connections are made.  By passing the &#8220;fuseaction&#8221; attribute, you will tell the Fusebox framework what action you want to be executed.</p>
<p>So, with the analogy to the &#8220;electric fusebox&#8221;, the framework is divided into &#8220;circuits&#8221; and &#8220;fuses&#8221;. Your application folders are called &#8220;circuits&#8221; and the ColdFusion templates are the &#8220;fuses&#8221;.</p>
<p>In this tutorial we will be referencing the Fusebox 5.51 XML version, not the non-xml one (sort of OO).  Let&#8217;s start by downloading the <a title="Fusebox 5.51 Core Files" href="http://fusebox.org/go/fusebox-downloads/core-files" target="_blank"><strong>Fusebox 5.51 Core Files</strong></a>, select the first link: Official FB5.5.1/CFMX core files (v5.5.1).</p>
<p>Unzip the contents to a folder named &#8220;fusebox5&#8243; inside your web application root if you <strong>DO NOT</strong> have access to the ColdFusion administration site. Otherwise, extract the contents to a folder outside your web root and then map it as &#8220;/fusebox5&#8243;. Doing that, you will be able to have multiple websites using the same Fusebox core installation.</p>
<p>Your Fusebox core structure should be like <em>Figure 1.1</em> side.</p>
<div id="attachment_785" class="wp-caption alignright" style="width: 234px"><img class="size-full wp-image-785" title="FBTutorial-01-003" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-003.jpg" alt="Figure 1.2" width="224" height="82" /><p class="wp-caption-text">Figure 1.2</p></div>
<p>We are going to create a web application for a  store called FBTutorial.  Here are the initial application requirements:</p>
<ul>
<li> Home Page with News Articles</li>
<li> Contact Page &#8211; form</li>
<li> Products page &#8211; catalog</li>
<li> Shopping Cart</li>
</ul>
<div id="attachment_783" class="wp-caption alignright" style="width: 108px"><img class="size-medium wp-image-783 " title="FBTutorial-01-001b" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-001b-122x300.jpg" alt="Figure 1.3" width="98" height="240" /><p class="wp-caption-text">Figure 1.3</p></div>
<p>I know two ways of creating the MVC structure for a Fusebox application. One is most used by creating 3 folders: <em>_model</em>,<em> _view</em> and <em>_controller</em> (the underscores are for placing the folders on top of the other regular ones), and inside those folders we would put the Fusebox circuits.</p>
<p>I find that more complicated and less modular. Any maintenance you need to do, you will have to look at the subfolders inside other subfolders, etc&#8230; (<em>figure 1.3</em>)</p>
<p>If you want to turn a circuit into a module that could be copied to other application, the better approach should be creating the circuits first, and then inside each circuit you create the folders &#8220;model&#8221; and &#8220;view&#8221;, being the circuit root itself working as the &#8220;controller&#8221;.</p>
<p>So I chose the second structure by creating the circuit folders and</p>
<div id="attachment_782" class="wp-caption alignright" style="width: 120px"><img class="size-full wp-image-782 " title="FBTutorial-01-001" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-001.jpg" alt="Figure 1.4" width="110" height="153" /><p class="wp-caption-text">Figure 1.4</p></div>
<p>then their subfolders model and view (<em>Figure 1.4</em>).  Here is how we will create the application structure:</p>
<ul>
<li> FBTutorial
<ul>
<li> circuits
<ul>
<li> forms</li>
<li> home</li>
<li> news</li>
<li> products</li>
<li> shopping</li>
</ul>
</li>
<li>other folders&#8230;</li>
</ul>
</li>
</ul>
<p>Now, inside each circuit folder, we will create the folders &#8220;<em>model</em>&#8221; and &#8220;<em>view</em>&#8220;. You decide</p>
<div id="attachment_786" class="wp-caption alignright" style="width: 132px"><img class="size-full wp-image-786 " title="FBTutorial-01-004" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-004.jpg" alt="Figure 1.5" width="122" height="145" /><p class="wp-caption-text">Figure 1.5</p></div>
<p>if you want to prefix them with underscore &#8220;_&#8221;, since you will not have any other folder in the circuits.</p>
<p>After creating all the necessary folders, we need to create empty control files in each folder. Those files will be named &#8220;circuit.xml.cfm&#8221;, which are XML files but with the extention CFM so they cannot be read by the browser without being parsed by ColdFusion. Just create the empty files for now.</p>
<p><em>Figure 1.5</em> shows the new structure with the XML files.</p>
<p>Do not worry about the empty files, we will fill them in later.</p>
<div id="attachment_788" class="wp-caption alignright" style="width: 140px"><img class="size-full wp-image-788 " title="FBTutorial-01-005" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-005.jpg" alt="Figure 1.6" width="130" height="96" /><p class="wp-caption-text">Figure 1.6</p></div>
<p>I&#8217;m just preparing the application structure before starting coding.</p>
<p>Now, let&#8217;s create the Fusebox required and optional files on the application root.  Starting with the <em>Application.cfc</em> (capital &#8220;A&#8221;),<em> fusebox.appinit.cfm</em>, <em>fusebox.init.cfm</em>, f<em>usebox.xml.cfm</em> and <em>index.cfm</em> (create those empty files and we&#8217;ll work on them next. Your structure now should be like <em>Figure 1.6.</em></p>
<h3>Application Root</h3>
<p>Let&#8217;s start now working on the Fusebox files on the application root. First of all, the <em>Application.cfc</em> component which is always the first to run on each request.<br />
The basic methods in the Application.cfc component are:</p>
<ul>
<li> onApplicationStart,</li>
<li>onApplicationEnd,</li>
<li>onSessionStart,</li>
<li>onSessionEnd,</li>
<li>onRequestStart</li>
</ul>
<p>You may have additional methods like onRequestEnd, onError&#8230; but right now we are interested in the Fusebox method:<strong> onFuseboxApplicationStart</strong>. That method is called when the Fusebox application initiates. It replaces the template <em>fusebox.appinit.cfm</em> in the application root. So if you may decide to use this method instead of that template, then it’s one less file to maintain.</p>
<p>Here is our <em>Application.cfc</em> template:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre>
<pre>&lt;cfcomponent extends=&quot;fusebox5.Application&quot; output=&quot;false&quot;&gt;
&lt;cfscript&gt;
this.name = right(REReplace(expandPath(&#039;.&#039;),&#039;[^A-Za-z]&#039;,&#039;&#039;,&#039;all&#039;),64);
this.applicationTimeout = createTimeSpan(0,6,0,0);
this.sessionManagement = true;
this.sessionTimeout = createTimeSpan(0,0,30,0);
this.clientManagement = true;
this.mainDSN = &quot;myDSN&quot;;
this.webmasterEmail = &quot;myEmail@myDomain.com&quot;;
&lt;/cfscript&gt;
&lt;!--- trap non-index.cfm requests - must be outside onXxxYyy() handlers ---&gt;
&lt;cfif right(cgi.script_name, len(&quot;index.cfm&quot;)) neq &quot;index.cfm&quot; and
right(cgi.script_name, 3) neq &quot;cfc&quot;&gt;
&lt;cflocation url=&quot;index.cfm&quot; addtoken=&quot;no&quot; /&gt;
&lt;/cfif&gt;
&lt;cffunction name=&quot;onApplicationStart&quot; returntype=&quot;boolean&quot; output=&quot;false&quot;&gt;
&lt;cfreturn True&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onApplicationEnd&quot; output=&quot;false&quot;&gt;
&lt;cfargument name=&quot;applicationScope&quot; required=&quot;true&quot; /&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onSessionStart&quot; output=&quot;false&quot;&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onSessionEnd&quot; output=&quot;false&quot;&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onFuseboxApplicationStart&quot;&gt;
&lt;cfset super.onFuseboxApplicationStart() /&gt;
&lt;!--- code formerly in fusebox.appinit.cfm ---&gt;
&lt;cfif not structKeyExists(application,&quot;mainDSN&quot;)&gt;
&lt;cflock name=&quot;mainDSN&quot; type=&quot;exclusive&quot; timeout=&quot;10&quot;&gt;
&lt;cfset application.mainDSN = this.mainDSN /&gt;
&lt;/cflock&gt;
&lt;/cfif&gt;
&lt;/cffunction&gt;
&lt;cffunction name=&quot;onRequestStart&quot;&gt;
&lt;cfargument name=&quot;targetPage&quot; /&gt;
&lt;cfscript&gt;
super.onRequestStart(arguments.targetPage);
//code formerly in fusebox.init.cfm
self = myFusebox.getSelf();
myself = myFusebox.getMyself();
if (listFirst(CGI.SERVER_NAME, &quot;.&quot;) == &quot;www&quot;) {
FUSEBOX_PARAMETERS.mode = &quot;production&quot; ;
} else {
FUSEBOX_PARAMETERS.mode = &quot;development-circuit-load&quot; ;
}
// request scope
request.applicationName = this.name;
request.mainDSN = this.mainDSN;
request.webmasterEmail = this.webmasterEmail;
request.baseDir = GetDirectoryFromPath(GetBaseTemplatePath());
request.componentPath = &quot;assets.components.&quot;;
request.imagePath = &quot;assets/images/&quot;;
request.cssPath = &quot;assets/css/&quot;;
request.jsPath = &quot;assets/js/&quot;;
request.flashPath = &quot;assets/multimedia/&quot;;
request.videoPath = &quot;assets/multimedia/&quot;;
request.ppsPath = &quot;assets/multimedia/&quot;;
&lt;/cfscript&gt;
&lt;/cffunction&gt;
&lt;/cfcomponent&gt;</pre>
</div>
<p>Now, here is the deal. Since the Fusebox core also has an Application.cfc with the same methods, we need to extend our Application.cfc to the Fusebox one and make use of the &#8220;call super&#8221; to invoke those methods first in order to use ours. On the first line, we extend the component. Remember to map /fusebox5 in your ColdFusion adminstration to the folder were you saved the core files.</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
</pre>
<pre>&lt;cfcomponent extends=&quot;fusebox5.Application&quot; output=&quot;false&quot;&gt;</pre>
</div>
<p>The method onFuseboxApplicationStart must have the call super:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
</pre>
<pre>&lt;cffunction name=&quot;onFuseboxApplicationStart&quot;&gt;
&lt;cfset super.onFuseboxApplicationStart() /&gt;
… … …</pre>
</div>
<p>onRequestStart should have also the call super:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
</pre>
<pre>&lt;cffunction name=&quot;onRequestStart&quot;&gt;
&lt;cfargument name=&quot;targetPage&quot; /&gt;
&lt;cfscript&gt;
super.onRequestStart(arguments.targetPage);
… … …</pre>
</div>
<p>Some code that was formerly in fusebox.init.cfm:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
</pre>
<pre>self = myFusebox.getSelf();
myself = myFusebox.getMyself();
if (listFirst(CGI.SERVER_NAME, &quot;.&quot;) == &quot;www&quot;) {
FUSEBOX_PARAMETERS.mode = &quot;production&quot; ;
} else {
FUSEBOX_PARAMETERS.mode = &quot;development-circuit-load&quot; ;
}</pre>
</div>
<h4>Fusebox.init.cfm</h4>
<p>We basically wrote all the necessary code for starting with the Application.cfc, now let&#8217;s concentrate on the Fusebox template fusebox.init.cfm. It is included by the framework at the start of every request. It is included within a cfsilent tag so it cannot generate output. It is intended to be for per-request initialization and manipulation of the fuseaction variables.</p>
<p>You can set attributes.fuseaction, for example, to override the default fuseaction. Fusebox 5.1 and later &#8211; set variables implicitly from the Fusebox itself.</p>
<p>Could also modify the self location here:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
</pre>
<pre>&lt;cfset myFusebox.setSelf(&quot;/myapp/start.cfm&quot;) /&gt;</pre>
</div>
<p>For now, just write the following code in your fusebox.init.cfm template:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
</pre>
<pre>&lt;cfprocessingdirective suppresswhitespace=&quot;true&quot;&gt;
&lt;!--- some future code here ---&gt;
&lt;/cfprocessingdirective&gt;</pre>
</div>
<h4>Index.cfm</h4>
<p>The index.cfm template will have only one statement:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
</pre>
<pre>&lt;cfinclude template=&quot;/fusebox5/fusebox5.cfm&quot; /&gt;</pre>
</div>
<p>In a Fusebox application the index.cfm template has no use other than to include the framework.</p>
<h4>Fusebox.xml.cfm</h4>
<p>The last file on the application root we have to work on is the fusebox.xml.cfm, which is the file that controls all the fusebox circuits, parameters, classes, plugins and global actions.<br />
In the &#8220;circuits” block we define the paths and aliases for the circuits. You may chose any name as an alias to a circuit, does not have to be the same name of the folder, you will see below that we are calling “cart” the circuit in the folder “shopping”.<br />
The “parameters” block contains Fusebox default settings, and it is customizable.<br />
Here is our fusebox.xml.cfm file:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
</pre>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE fusebox&gt;
&lt;!--Example fusebox.xml control file. Shows how to define circuits, classes, parameters and global fuseactions. This is just a test namespace for the plugin custom attribute example --&gt;
&lt;fusebox xmlns:test=&quot;test&quot;&gt;
&lt;circuits&gt;
&lt;!-- Home circuit --&gt;
&lt;circuit alias=&quot;home&quot; path=&quot;circuits/home/&quot; parent=&quot;&quot; /&gt;
&lt;circuit alias=&quot;mhome&quot; path=&quot;circuits/home/model/&quot; parent=&quot;home&quot; /&gt;
&lt;circuit alias=&quot;vhome&quot; path=&quot;circuits/home/view/&quot; parent=&quot;home&quot; /&gt;
&lt;!-- Forms circuit --&gt;
&lt;circuit alias=&quot;forms&quot; path=&quot;circuits/forms/&quot; parent=&quot;home&quot; /&gt;
&lt;circuit alias=&quot;mforms&quot; path=&quot;circuits/forms/model/&quot; parent=&quot;forms&quot; /&gt;
&lt;circuit alias=&quot;vforms&quot; path=&quot;circuits/forms/view/&quot; parent=&quot;forms&quot; /&gt;
&lt;!-- News circuit --&gt;
&lt;circuit alias=&quot;news&quot; path=&quot;circuits/news/&quot; parent=&quot;home&quot; /&gt;
&lt;circuit alias=&quot;mnews&quot; path=&quot;circuits/news/model/&quot; parent=&quot;news&quot; /&gt;
&lt;circuit alias=&quot;vnews&quot; path=&quot;circuits/news/view/&quot; parent=&quot;news&quot; /&gt;
&lt;!-- Products circuit --&gt;
&lt;circuit alias=&quot;products&quot; path=&quot;circuits/products/&quot; parent=&quot;home&quot;/&gt;
&lt;circuit alias=&quot;mproducts&quot; path=&quot;circuits/products/model/&quot; parent=&quot;products&quot; /&gt;
&lt;circuit alias=&quot;vproducts&quot; path=&quot;circuits/products/view/&quot; parent=&quot;products&quot; /&gt;
&lt;!-- shopping circuit --&gt;
&lt;circuit alias=&quot;cart&quot; path=&quot;circuits/shopping/&quot; parent=&quot;home&quot; /&gt;
&lt;circuit alias=&quot;mcart&quot; path=&quot;circuits/shopping/model/&quot; parent=&quot;cart&quot; /&gt;
&lt;circuit alias=&quot;vcart&quot; path=&quot;circuits/shopping/view/&quot; parent=&quot;cart&quot; /&gt;
&lt;!-- Layout circuit --&gt;
&lt;circuit alias=&quot;layout&quot; path=&quot;circuits/layout/&quot; /&gt;
&lt;/circuits&gt;
&lt;classes&gt;
&lt;/classes&gt;
&lt;parameters&gt;
&lt;parameter name=&quot;defaultFuseaction&quot; value=&quot;home.main&quot; /&gt;
&lt;!-- you may want to change this to development-full-load mode: --&gt;
&lt;parameter name=&quot;mode&quot; value=&quot;development-full-load&quot; /&gt;
&lt;!-- change this to something more secure: --&gt;
&lt;parameter name=&quot;password&quot; value=&quot;&quot; /&gt;
&lt;parameter name=&quot;strictMode&quot; value=&quot;true&quot; /&gt;
&lt;!-- These are all default values that can be overridden:
&lt;parameter name=&quot;fuseactionVariable&quot; value=&quot;fuseaction&quot; /&gt;
&lt;parameter name=&quot;precedenceFormOrUrl&quot; value=&quot;form&quot; /&gt;
&lt;parameter name=&quot;scriptFileDelimiter&quot; value=&quot;cfm&quot; /&gt;
&lt;parameter name=&quot;maskedFileDelimiters&quot; value=&quot;htm,cfm,cfml,php,php4,asp,aspx&quot; /&gt;
&lt;parameter name=&quot;characterEncoding&quot; value=&quot;utf-8&quot; /&gt;
&lt;paramater name=&quot;strictMode&quot; value=&quot;false&quot; /&gt;
&lt;parameter name=&quot;allowImplicitCircuits&quot; value=&quot;false&quot; /&gt;
&lt;parameter name=&quot;debug&quot; value=&quot;false&quot; /&gt; --&gt;
&lt;/parameters&gt;
&lt;globalfuseactions&gt;
&lt;preprocess&gt;
&lt;/preprocess&gt;
&lt;postprocess&gt;
&lt;/postprocess&gt;
&lt;/globalfuseactions&gt;
&lt;plugins&gt;
&lt;phase name=&quot;preProcess&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;preFuseaction&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;postFuseaction&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;fuseactionException&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;postProcess&quot;&gt;
&lt;/phase&gt;
&lt;phase name=&quot;processError&quot;&gt;
&lt;/phase&gt;
&lt;/plugins&gt;
&lt;/fusebox&gt;</pre>
</div>
<p>We define the circuits in the &#8220;circuits&#8221; block by assigning an alias to the path. In the application we will call the index.cfm passing the circuit,fuse and fuseaction we want to execute. Example:</p>
<div id="attachment_867" class="wp-caption alignright" style="width: 152px"><img class="size-full wp-image-867 " title="FBTutorial-01-007" src="http://ricardo.parente.us/wp-content/uploads/2009/08/FBTutorial-01-007.jpg" alt="Figure 1.7" width="142" height="90" /><p class="wp-caption-text">Figure 1.7</p></div>
<p>index.cfm?fuseaction=home.main<br />
index.cfm?fuseaction=products.showProduct&amp;productID=1234<br />
index.cfm?fuseaction=cart.addToCart</p>
<p>With Fusebox, everything is assembled in the root. The index.cfm loads Fusebox and it prepares the request to be served without the customer seeing in which folders the templates are.<br />
We added a circuit named &#8220;layout&#8221; which will handle all the layouts for our application. Since it is for the presentation layer, we do not have to create the &#8220;model&#8221; folder. <em>Figure 1.7</em> shows an updated version of our structure.</p>
<h4>Circuit.xml.cfm</h4>
<p>Now we are going to look at the<em> circuit.xml.cfm</em> file placed in all circuits.<br />
Let&#8217;s start with the &#8220;home&#8221; main circuit, the controller one&#8221; <em>/circuits/home/circuit.xml.cfm:</em><br />
For now we will not have any actions to call, just a display page to show the homepage, then our circuit.xml.cfm file will have the following code:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
</pre>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!-- home --&gt;
&lt;circuit access=&quot;public&quot; xmlns:cf=&quot;cf/&quot;&gt;
&lt;fuseaction name=&quot;main&quot;&gt;
&lt;do action=&quot;vhome.main&quot; /&gt;
&lt;/fuseaction&gt;
&lt;/circuit&gt;</pre>
</div>
<p>You noticed that we here we are calling an action on another circuit, the &#8220;vhome&#8221;, in the &#8220;view&#8221; part of the MVC, to display the homepage. If we had to calculate anything or grab any information from a database in order to populate that homepage, then we would call the &#8220;model&#8221; layer before the &#8220;view&#8221;.</p>
<p>The call to &#8220;index.cfm?fuseaction=home.main&#8221; will get to this circuit which will call the &#8220;vhome.main&#8221; fuseaction in the &#8220;view&#8221; area.  Subsequently that fuseaction, &#8220;vhome.main&#8221;, will include the template &#8220;dspMain.cfm&#8221; with the contents of the homepage, and then Fusebox will assemble the full page for ColdFusion to render to the browser.  Note that the attribute “access” for this circuit is set to “public”. That means it can be accessed by the web browser, it is a public fuse.</p>
<p>Here is the circuit.xml.cfm file in the &#8220;view&#8221; area:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
</pre>
<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE circuit&gt;
&lt;!-- vhome --&gt;
&lt;circuit access=&quot;internal&quot; xmlns:cf=&quot;cf/&quot;&gt;
&lt;fuseaction name=&quot;main&quot;&gt;
&lt;include template=&quot;dspMain.cfm&quot; required=&quot;true&quot; /&gt;
&lt;/fuseaction&gt;
&lt;/circuit&gt;</pre>
</div>
<p>In this case, the “access” attribute is set to “internal” which means this circuit can be only called by another circuit, it will not respond to browser calls.</p>
<p>The fuseaction “main” will include the template dspMain.cfm.<br />
Just for testing purpose, create the file dspMain.cfm with the following HTML code:</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
</pre>
<pre>&lt;h1&gt;Hello World&lt;/h1&gt;</pre>
</div>
<p>Now, let&#8217;s test the site. If you have ColdFusion Developer Edition installed in your machine, just browse to: &#8220;<em>http://localhost/FBtutorial</em>&#8220;. You do not have to specify any attributes, because the Fusebox configuration file (fusebox.xml.cfm) will take care of calling the default fuseaction &#8220;home.main&#8221;.<br />
You should get the page <strong>&#8220;Hellow World&#8221;</strong>.</p>
<p>On the next part we will start handling layouts.</p>
<p>I hope you have liked this tutorial and please feel free to comment if you have questions.</p>
<p><a title="Fusebox 5.51 with MVC Tutorial Part 2" href="http://ricardo.parente.us/2009/09/fusebox-5-51-with-mvc-tutorial-part-2/" target="_self"><strong>Part 2</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://ricardo.parente.us/2009/08/fusebox-5-51-with-mvc-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

