Halhelms
SIGN UP FOR MY NEWSLETTER

www.savorgold.com is top on wow gold and runescape gold and World of Warcraft gold provider list for trusted services. Their reputation seems to growing by the minute, which isn't surprising because they are one of the safest sellers of Gold. Delivery speed and customer service are very good. They aslo are giving some bonus items depending on the amount of gold you purchase.

 
 
Halhelms

Recent Comments

Recent Entries

RSS

Learning ColdBox: I

So...my first step is going to the ColdBox site to download the framework: http://www.coldbox.org/download. I created a coldbox directory directly under wwwroot. For now, I'm going with my idea of a Philosopher Battle game (see yesterday's post). (BTW, as Phil Nacelli pointed out, ColdBox comes with several sample applications already! Why not just one of these? See below...) So, let's start with creating a "Philosophy Game" app.

I want to do about as little as possible to get the app working. (BTW, if you just browse to the coldbox/ApplicationTemplates/SuperSimple/index.cfm, you can test to see if your setup is working.) I begin by copying coldbox/ApplicationTemplates/Advanced and renaming it to philosophy. Why the Advanced directory? Just a guess that, as I make the app more complex, I may find some sample code in there that will be helpful. (Throughout this exploration, I expect to make a lot of mistakes. I'm counting on you helpful guides to set me -- and all of us -- straight.)

I read through the excellent tutorial Jason Dean has beginning at http://www.12robots.com/index.cfm/2008/9/21/Building-an-Application-with-ColdBox-and-ColdSpring--Part-1. As I understand it, the ApplicationTemplates is where my individual sites can be created. At least, this is one way of doing it, I believe?

Question: can I take the philosophy directory and move it to the web root? If so, what do I need to do to make that work?

UPDATE: See Luis' response: moving the app to the web root is really simple. Nicely done, ColdBox!

While I'm awaiting an answer on that, I'll open up philosophy/config/Coldbox.cfc. My understanding is that's where the configuration stuff goes. In the past, ColdBox used an XML file (and still supports that, I believe?), but the move from XML is, for me at least, most welcome.

There's a single configure method that we'll use to individualize the philosophy application.

// coldbox directives
coldbox = {
//Application Setup
appName 		= "philosophy",
eventName 		= "event",
...

Within the configure method, I've exchanged the default appName value for my own: philosophy.

The next section is for development settings:

//Development Settings
debugMode               = true,
debugPassword           = "",
reinitPassword          = "",
handlersIndexAutoReload = true,
configAutoReload        = true false, // see Luis' comment below

I've changed some of the defaults here: my understanding is that these are good for development?

The next section, Implicit Events, looks like this:

//Implicit Events
defaultEvent            = "philosophy.index",
requestStartHandler     = "Main.onRequestStart",
requestEndHandler       = "",
applicationStartHandler = "Main.onAppInit",
applicationEndHandler   = "",
sessionStartHandler     = "",
sessionEndHandler       = "",
missingTemplateHandler  = "",

What are these for? As I understand it, events in ColdBox are really requests. I mention this because in some other systems, events are not so much requests as they are notifications that something has just taken place. I won't get us sidetracked talking about different meanings of event, though.

The defaultEvent is used when no event is specified. How might an event be specified? One way would be through the use of a search-engine-safe (SES) URL parameter -- for example: localhost/coldbox/ApplicationTemplates/philosophy/index.cfm/user/add where user indicates the event handler and new specifies the event.

To put it another way, events map to a method in a CFC found in philosophy/handlers directory. In the case of the URL just show, Coldbox would look in the events directory for a file called User.cfc and for a method within that CFC called add. In addition to a specified event ( or the defaultEvent if none was specified), it looks like we can specify methods to run during the following phases of the application:

  • when the application starts
  • when the session starts
  • when the request starts
  • when the request ends
  • when the session ends
  • when the application ends
  • when a template is requested that doesn't exist

It's certainly nice to be able to explicitly set these.

The next section, Extension Points, I'm going to skip for now. This is a little deeper than I want to get into for my first app -- limited cranial storage and processing and all that. In fact, I'm going to save my Coldbox.cfc file now. We'll come back to this later, I'm sure.

Luis Majano has a nicely done graphic explaining the ColdBox lifecycle here: http://wiki.coldbox.org/wiki/RequestLifecycles.cfm. ColdBox supports the Model-View-Controller design pattern, so normally, I would want a request to be handled by a controller that would use model and/or view resources to accomplish its responsibility. In ColdBox parlance, controllers are called event handlers, I believe?

For now, I just want to say "Hello, World" -- and to do this, I'm going to use a very nice, new feature of ColdBox 3 called implicit view rendering. From the docs:

Implicit View Rendering

You can now render views without the need of creating events for them. If you are building a prototype or migrating from legacy code into the framework, this will be a great asset. So let's say you want to execute the event: site.contact this should map to a site.cfc and contact() method. However, if they do not exist, the framework will look for a view called: views/site/contact.cfm and if it finds it, it will execute it!

My goal with this first step of my app is just to get the app to say hello. So, for now, I'll have no controllers and no actions -- just the template I wish the user to view. These are located, logically enough, in the views directory. I'll use this URL: localhost/coldbox/ApplicationTemplates/philosophy/index.cfm/hello/world. So, if I have it right, I should be able to create a subdirectory within views called hello and within that subdirectory, create a file called world.cfm.

Pointing a browser at that URL produces this:

Hey, that worked!

Ok, obviously, there's a lot more to be covered, but we did get ColdBox installed and running. Next, we'll go a little deeper, creating an event handler and specifying an event (rather than using implicit view rendering).

My code, so far: https://github.com/halhelms/ColdBox-Sample-App/tree/step1

Your corrections, comments, questions are much desired!


A Note About This Learning Style

While this trial-and-error style isn't the most efficient, for some of us, it's one of the best ways of incorporating new information. It allows us to build a mental model of how a system works, which is vital since we want to master a new subject. Of course, different people have different learning styles: one of my good friends likes to read RFCs to learn new technology!

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Luis majano's Gravatar Great stuff Hal. One pointer, the configAutoReload flag might be a good idea to set tofalse. If not each request looks like the first request always! It was designed to try Out app start behavior easily. On phone now so will answer other questions later.
# Posted By Luis majano | 4/1/11 11:49 PM
Luis majano's Gravatar To answer your first question about moving it to the root. You don't do anything. Cold box auto calculates a setting called app mapping. This is where the app lives in the web root. Of course if it is in the root the app mapping is empty. If you are embedded in a directory then that path is the app mapping. This is auto calculated but if you will be using remote proxies web services event gateways then this setting must be set in the Application.cfc to tell cold box exactly where the app is located if embedded. If in the root, then like my friend mark Mandel says, no worries mate
# Posted By Luis majano | 4/2/11 1:46 PM
Richard Herbert's Gravatar I personal style point: I tend to put my Implicit Event methods in their own component called implicitEvent.cfc for grouping and easy identification.

On general configuration, I'd suggest you find some time to look at the "environments" key in Coldbox.cfc to control any settings on a per-environment basis. Personally I set the default settings to those for Production and then overwrite as required for the Staging and local Development environments - http://wiki.coldbox.org/wiki/ConfigurationCFC.cfm#...
# Posted By Richard Herbert | 4/4/11 5:35 AM
Hal Helms's Gravatar @Richard Am I right in thinking then that all event handlers are loaded on app start?
# Posted By Hal Helms | 4/4/11 12:09 PM
Richard Herbert's Gravatar Sure on application start or framework reinit (?fwreinit=1) but on request it is dependant on your settings.

Like I said, in Production I have handlerCaching, eventCaching set to true and handlersIndexAutoReload set to false. In Development I have them set to the opposite.
# Posted By Richard Herbert | 4/4/11 1:25 PM
 
   
Clicky Web Analytics