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

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
April 01, 2024
Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024