Seminar On How to Setup ColdFusion Application using Fusebox MVC architecture
How to Setup a ColdFusion Application using Fusebox MVC Architecture
This seminar is for learning the basics of Fusebox, Fusebox Installation and how to setup ColdFusion application using Fusebox.
Hello all, I am Manjeet and today I will present a seminar on how to setup a ColdFusion application using Fusebox MVC architecture. Today I will discuss what is a framework and why we need it. What is Fusebox, installing Fusebox, MVC in Fusebox and setting up ColdFusion app using Fusebox. Coming to next slide, framework. We are aquainted with framework. I will mention a few points.
Framework makes it easy to work with complex technologies. It ties togther discrete objects into something more useful. It forces the team to implement the code in a way that promotes consistent coding, fewer bugs and more flexible applications.
Everyone can easily test and debug the code, even code that they didn't write. Next, what is a Fusebox? Basically its a framework for building web applications. It's meant to make your application easier to create and maintain. It makes team development easy. It does this by helping you structure and break things down into discrete pieces.
Next, Fusebox elements. A Fusebox has 4 elements. Circuit, fuseaction, fuses and … first fusebox application is made up of circuits. It corresponds to a directory in your application. Within each circuit are one or more fuse actions. Means, if you are building an application and it has 2 models. We create 2 folders and functionality related to admin is inside admin folder and functionality related to user is in user folder. Also we can create a common folder to have common functionality, like login, registration, forgot password, etc.
We will need 3 circuits for 3 folders. Fuseaction is just a request handler and finally it does its work by executing one or more fuses. These are responsible for handling a request. It just exectues the fuses. So now, what is a fuse? They are individual ColdFusion markup language templates such as display files. Means all cfm in coldfusion are called fuses.
Now how we can install fusebox. You can just go to google, type fusebox, now you have www.fusebox.org. Click on it, here you go to download section. Now you can see fusebox presents in either core files and with some skeleton application. If we are going to download fusebox core files, then we only have core files and also skeleton files.
Skeleton file means, if you will download this set of core files then it will already give you structure of your application, like some folders, circuits etc. are already created. You need to follow the process and build the application. But if you download only core files, you have to structure your application, create circuits, folders etc.
you need to download these core files, then unzip it and you will get a folder fusebox file. You have to place that folder in root directory of the application. If you download the fusebox core files then you have 3 options. Either you can place in shared directory or place inside web root or you can place in application but above the web root. In this case we will use second as an example.
This is the process to download and install. I am showing you here. This is my demo folder. Next, for your application you can have one application.cfc so you need to create one. If you want this application to use fusebox files, you need to use extends attribute inside ColdFusion component tab which will extend the fusebox file properties.
Then you can use variables or functions in application.cfc as in your actual application. I need some parameters for application.cfc. I put some important parameters here. Here you can see first I put fusebox parameters.mode = development full load. It has 2 .. either development or production. Later I will explain what is difference when you put this in development full mode or when in production full mode. When you pass some parameters in the URL call you have to enable these parameters, the fusebox will read it as a fuseaction. I will show you this. Now default fuseaction is, when you have not called any fuseaction, then by default it will call as main.welcome.
In fusebox, we do not need to write anything inside index.cfm, we can keep it empty. There are 2 important files for fusebox, one is fusebox.xml.cfm file and other is circuit.xml.cfm file. Fusebox.xml.cfm file. Basically you create your parameters, declaring classes, plugins and global fuse actions. Basically we use XML tag based things to write them.
First fusebox.xml.cfm, here I have declared the XML version, you just include this XML file. Initially I created fusebox. It opens the fusebox in your application. Then circuits. As I said in fusebox all directories cor respond to a circuit. We can declare no. of circuit in fusebox.xml.cfm. Here I have only created 1, but it can be more.
You can give an alias name and path and parent. Fusebox is made of circuits, so here I have declared the circuits, now contains one or more fuseactions. Fuse action executes the fuses, that is cfm templates. Advantage of fusebox is, you can all pages only by calling index.cfm page. I am showing you.
As I have not passed any fuseaction in UI, how it opens Hello World. First it goes to application.cfc and finds that default fuseaction is main.welcome. Left portion is always your circuit and right side is fuseaction. So it will search for circuit, it will go to fuseaction.xml file and find the main .. so same in application we have a circuit.
Next, MVC in fusebox. Its basically a 3 tier architecture where we separate our business logic, control logic and presentation logic from each other. The benefit of this is that in multiple development will be possible and one developer can work on logic part, on presentation part and on .. part. So its makes development faster, easier and very easy to maintain it.
We will see how to use MVC architecture in fusebox. We have to setup an MVC architecture for setting up the coldfusion app. Now for this I have another example. I have assumed that one application has 2 models, admin and user and have some common functionality so for that we have common module. We download fusebox file and unzip in this folder. Then create 3 folder, admin, user and common. Then application.cfc fusebox.xml.cfm and index.cfm as the empty files.
First go to application.cfc, the same thing, we have extended here and declare the parameters. First index request will be done. When index.cfm page is requested, this default fuseaction called. So common is circuit and view login is fuseaction. Now you can go to common folder. This is the circuit I need. Then there is a view button. I can see I am not actually executing … it means when you want to call a fuseaction or other circuit, then you need to use do action.
I cannot call login.cfm file from this circuit as it belongs to a different directory and for this we have circuit.xml.cfm file. So lets open this file, you can see the access is public, which means a circuit with access public can directly call from the URL. But you can see, this has internal, so it can be called by other .. in application but not by the URL.
For this I have called the common view login, which is your circuit. So now how this will work. When I will click on this log in button, it will call that page. Lets make a registration, give user name and register. In login.cfm page you can see on view register I am calling a fuse action. When user passes username and password and clicks on register button, registration screen shows up. I have 3 different directories, one is admin, one is user and one is common. For each directory I should have a circuit. I have a circuit for each of these. As its MVC architecture we have created 3 different folders, model, view and controller. It will act as directory and every cfc will have a class.
Next, there are lot of frameworks for ColdFusion. So are fusebox and mach 2 or model glue competing frameworks? Answer is not really. They represent 2 different approaches to building an application. Both mach2 and model glue require object oriented approach for development. But fusebox doesn't require it but can support it if necessary.
If you are going to use mach 2 or model glue then you have to be good at object oriented programming. But fusebox doesn't force you to write object oriented, but if you need that concept then it supports it. This is the best advantage of using MVC. I will explain about development and production modes.
The modes can be set to various development modes , either production or development. The difference is that development full load reparse the XML files only if they have changed and rebuilds all fusebox memory structures on every request. In development circuit load does not reload the fusebox.xml file but does reload any circuit.xml file required.
In development mode if you are making changes in circuit, means adding a fuse XML or .. it reparses the XML and when you make any new changes. But in production mode it doesn't make any changes. To reflect that we have one solution. You can just change your mode from production to development and then make necessary changes and update changes to production server and then again change the mode.
So we have new things in fusebox 5, like we can forcefully reload the Fusebox by passing some parameters. Reloading a Fusebox means when the fusebox is called for first time, it automatically creates a .. folder in application root path. We can see this. Here there are some parsed files. Wen you are in development mode and making changes, it will reparse the page and they will be created again.
But in production mode it will only take the files from parsed folder so it won't reflect the changes. To reflect changes you can change the mode. Luckily we have some parameters which we can set in URLs so in production mode as well it will reparse the changes.
In model view controller without XML. As we saw we created MVC with … but in Fusebox 5.5 we can create MVC architecture without XML. It will be fully object oriented concept.
In my next presentation I will come up with more object oriented programming approach while setting up coldfusion app using MVC architecture. These are the references used in this seminar. Thanks all.
Coldfusion, Fusebox, MVC, Web Development