Blog

CommandBox: CFML SandBox

Nathaniel Francis February 18, 2015

Spread the word

Nathaniel Francis

February 18, 2015

Spread the word


Share your thoughts

CommandBox = CLI for CFML

For a long time, the CFML community has wanted a CLI tool for REPL, developer productivity, tool interaction, embedded CFML server, and application scaffolding. CommandBox provides those elements.

But what about just playing with CFML? There's the REPL in CommandBox of course, but what if I want to do something a bit larger than that and really play with the language?

SandBox = CommandBox + ColdBox

Creating a SandBox environment is surprisingly easy. All you need are 2 things:

  1. A working version of CommandBox
  2. A simple ColdBox 4.0 install

Why ColdBox?

When most people see "ColdBox", they think of the full-fledged, super extensible framework, according to its reputation. But there are some very simple, "out of the way" aspects that ColdBox provides. One of which will help us setup a SandBox within which we can play with CFML in a larger scope than the CommandBox REPL provides.

That feature is: implicit views. For a long time, the ColdBox framework has employed a mechanism called implicit views. You simply place a .cfm file into the directory's views folder and ColdBox will implicitly map to that .cfm file even if it doesn't have a corresponding event handler. Simply put, write a .cfm file and we can hit it without any extra hoopla or work. Pretty simple.

Armed with ColdBox 4.0's implicit views and CommandBox's embedded server, you can setup a quick and easy SandBox that can run right in your local system.

 

NOTE: this is not about learning ColdBox per se (although that's pretty cool too). It's about being able to simply play with CFML beyond the CommandBox REPL.

 

SandBox Setup

Step #1: mkdir/cd

Start by opening CommandBox and "cd" to whatever directory you want to make a simple app.

Then make a directory to house your SandBox.

mdir mySandBox
cd mySandBox

Step #2: simple ColdBox install

Now, put in a simple ColdBox 4.0 installation into the directory. You don't need any additional modules or libraries, the basic ColdBox install is all you need.

coldbox create app sandbox --installColdBox

If this is your first ColdBox install, it will take a little bit to get the files from ForgeBox. If you've made a ColdBox app before, CommandBox will load the files from your local artifacts in a moment.

Now, you can look in your mySandBox directory and see the files that the ColdBox install setup for you.

Step #3: make a .cfm file

To start SandBoxing, you're going to make a simple .cfm file from CommandBox.

coldbox create view hello

If you check your directory, under the views folder, CommandBox has generated a simple "hello.cfm" file.

Open that "hello.cfm" file in a text editor and you will see this:

<h1>hello view</h1>

Pretty simple.

Step #4: start the embedded server

Now to make it live: go back to CommandBox and simply enter:

start

This will start CommmandBox's embedded server with the SandBox application in your default browser.

What you'll see come up in your browser is a standard Welcome To ColdBox! page that gives detailed information of your simple ColdBox app.

Now you need to get to your "hello.cfm". ColdBox will map to the "hello.cfm" file by appending the name of the file to index.cfm. Simply enter this in your browser's URL field:

127.0.0.1:<port#>/index.cfm/hello

And you will see this:

Just the beginning

This is just the beginning. Now you can go to your text editor and start playing with CFML right there. On browser refresh, you'll see the changes go live. We got a real CFML SandBox with nothing more than CommandBox and a simple ColdBox install (thanks to ColdBox's implicit view mechanism and CommandBox's embedded server).

As an example, in my own SandBox, I went my "hello.cfm" file and entered the following:

The <h1>hello view</h1> was already there (created automatically from Step #3). I simply added a dump of now() and my session scope.

Refresh the browser and I get this:

There. Now I'm doing more than the CommandBox REPL provides. I'm able to genuinely SandBox with CommandBox.

Happy SandBoxing!

Add Your Comment

Recent Entries

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023