Getting Our Project Started
Last week we were talking about using ColdBox and Coldspring to run our project. Let's take a look at how we actually make this happen.
The first thing we need to do is download the latest stable release of both frameworks. You can download ColdBox from http://www.coldbox.org/index.cfm/download and Coldspring from http://www.coldspringframework.org/. The docs recommend we unpack the archives directly unto our web root. Personally I do it slightly differently. Using the power of application-specific mappings, we can place them pretty much anywhere we want, as long as we create a mapping for them in our application.cfc file. On my install, I have a frameworks folder in my web root and within it version-specific folders for each framework
frameworks/
coldbox_2.6.2/
coldbox_2.6.3/
coldspring_1.2/
This allows me to tell each distinct application which version of each framework to use. The next step is copying over the application template from ColdBox's install folder to where we want our application to be. In the root of our new folder, there are now two files of interest: Application.cfc and Application_noinheritance.cfc. This is where we get to choose which one we want.
- Application.cfc
- This file extends the ColdBox framework. Since the link to the framework is (and has to be) in the first line, there is no way to specify where to find the appropriate version without hard-coding it in the extends attribute.
- Application_noinheritance.cfc
- This version extends no other cfc's. This is perfect for us, since we now have plenty of room to create our mappings before the application creates a reference to the framework.
At this point, we can safely delete Application.cfc and remove _noinheritance from the other file's name. In our new Application.cfc file, we'll add a couple of lines just before the application sets it's root path:
<cfset this.name = hash(getCurrentTemplatePath())>
<cfset this.sessionManagement = true>
<cfset this.sessionTimeout = createTimeSpan(0,0,30,0)>
<cfset this.setClientCookies = true>
<cfset this.mappings[ "/coldbox" ] = expandPath( "/frameworks/coldbox_2.6.3" ) />
<cfset this.mappings[ "/coldspring" ] = expandPath( "/frameworks/coldspring_1.2" ) />
<cfset this.mappings[ "/squash" ] = getDirectoryFromPath(getCurrentTemplatePath()) />
<cfset COLDBOX_APP_ROOT_PATH = getDirectoryFromPath(getCurrentTemplatePath())>
<cfset COLDBOX_CONFIG_FILE = "">
<cffunction name="onApplicationStart" returnType="boolean" output="false">
Notice the three lines starting with "<cfset this.mappings". These three lines do the same thing than actually going into your admin and creating three mappings, with one major difference: the mappings are exclusive to this application. That means that you could actually have a /coldbox mapping in your admin but within this application it would use a different path for it.
A mapping is a way for your application to link to a specific path on your system, without having to write the entire string out each time. When
The first two lines are for the frameworks. The mappings require an absolute path (c:\path\to\your\folder) which is why we need to use expandPath. The third line is a shortcut I use for linking to the application's folder. By retrieving the directory from the current template (Application.cfc) we have a direct link to the application's root. As a bonus, even if we move our application (new folder, new server, etc.), it will always have a squash mapping linking to it's exact installation location.
ColdBox is great for using IoC frameworks: out of the box it can handle both Coldspring and Lightwire. For this project I've decided to use Coldspring. So ColdBox knows which choice I've made I'll tell it in the coldbox.xml.cfm file, located in the config folder of our install. In the settings block there are two nodes that we need to make sure are set appropriately: IOCFramework and IOCDefinitionFile:
<Setting name="IOCDefinitionFile" value="config/coldspring.xml.cfm" />
With these two little lines of code ColdBox now knows which IoC framework we want to use and where to find it's definition file. Now then, what do we put in that definition file? Well, that's s story for another day. At this point, ColdBox and Coldspring stand ready, but all that's in the application is the default event. We can call it by hitting the application's index.cfm file. Ain't it pretty? We'll strip all of that out tomorrow morning. In the meantime, don't forget to eat your vegetables.


There are no comments for this entry.
[Add Comment] [Subscribe to Comments]