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

BoxLang 1.0.0 Beta 23 Launched

BoxLang 1.0.0 Beta 23 Launched

The latest release of BoxLang, Beta 23, marks a significant step forward in our journey to create the ultimate dynamic language for the JVM. Packed with powerful new features, important bug fixes, and thoughtful optimizations, this update is designed to make your development experience smoother, faster, and more reliable, especially after now starting to take 100s of comments and bug reports from our community.

Luis Majano
Luis Majano
November 23, 2024
TestBox Latest Updates and News!

TestBox Latest Updates and News!

We’re thrilled to have launched the new TestBox website and TestBox 6.0! If you haven’t had a chance to explore yet, visit TestBox to discover updated documentation, powerful resources, and features that make testing more efficient than ever.

Maria Jose Herrera
Maria Jose Herrera
November 21, 2024
Is Your ColdFusion Application Ready for the Future?

Is Your ColdFusion Application Ready for the Future?

In a rapidly evolving digital world, maintaining performance, security, and scalability for ColdFusion applications is more challenging than ever. Whether you're using Lucee or Adobe ColdFusion, legacy systems can become a bottleneck for growth, innovation, and user satisfaction. The need to future-proof your ColdFusion applications has never been more critical.

But where do you start?


The Hidden Costs of an Outdated ColdFusion Application

As you...

Cristobal Escobar
Cristobal Escobar
November 21, 2024