First Coldbox application

Hi all –

I’m developing my first Coldbox application, so I think I’m missing a few things.

We’re using Coldbox 3.8 running on the coldbox-devbox portable installation. The application in the coldbox-devbox currently runs at localhost:8081/subdirectory

When I pull the code and attempt to run it at Amazon, where it will run in the root of the web folder, then all of the mappings for my models are off.

For example, in the coldbox-devbox environment, I have to say getModel(“subdirectory.model.user.service”) for Coldbox to load the service. At Amazon, that same call doesn’t work because it’s not in a subdirectory.

I could add a per-application mapping like <cfset mappings["/subdirectory"] > to make it work at Amazon, but I can’t figure out how to do that as part of the environment detection code in Coldbox. I’ve also seen something about using #appmapping#, but that variable doesn’t exist, even though it’s mentioned in Coldbox.cfc as being available in the variables scope and auto-calculated by Coldbox.

Any help would be appreciated!

Thank you!

post some debug.

Rob,

When developing any application, whether it be running in Native ColdFusion or ColdBox, you really should be developing to your production environment. That means if it is going to be deployed to a web root, then you should be developing with that structure in development as well.

Otherwise you will experience what you are experiencing.

Rob, welcome to ColdBox!

The appmapping is a ColdBox setting you can generally retrieve with getSetting(). However, with a bit of WireBox magic you shouldn’t need to worry about that. by default, WireBox will add your model folder as a scan location. That means you SHOULD be able to just do getModel(‘user.service’) and that path will be searched for in your models folder.

Now, we can take this a step further and you can add mappings for your models so you can access them simple as getmodel(“service”). Individual models can be mapped with:
map(“service”).to(“path.to.service”) in your /config/wirebox.cfc file.

My preference is to use the very handy mapDirectory() function in your WireBox config file:

mapDirectory(“model”);

Now, instead of searching for a model the first time you request it in your scan locations, this function tells WireBox to do a recursive search on the model directory at startup and map every CFC it finds.

You might need to do something like this:

if(len(appMapping)) {
modelPrefix = appMapping & ‘.’;
} else {
modelPrefix = ‘’;
}
mapDirectory("#modelPrefix#model");

So, it is possible to make your app smart enough to follow the app mapping, but like Andrew said it is a lot simpler if you can just keep your development and production environments the same. DevBox is meant to just get you up and running quickly, but it is still very configurable. It uses Resin under the hood (which is a servlet container like Tomcat). If you wish, you can edit /cong/resin.xml and add additional tags there and then configure a host file entry on your local machine so myDevSite.com resolves to localhost and is served by Resin. You would still use the same port, just a different hostname.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad –

Thanks for the quick response.

So, it looks like I don’t have a Wirebox.cfc in my Coldbox config directory, so I suppose I should create that first. But, that puts me back at the beginning - subdirectory.config.Wirebox is required in the devbox environment, and I’m guessing config.Wirebox will be required at Amazon.

Looks like I’ll need to reconfigure devbox.

Wait - no, I’m a dumbass.

I was able to set binder = “wirebox” and it found it!

Woo!

I don’t think you understand that correctly. Yes, you need to create a WireBox.cfc file in the config directory but you don’t need to do anything different with the WireBox config between devbox and amazon. The ColdBox framework automatically uses the app mapping when it loads to find the correct config directory and it will load the WireBox config file without issue. All you need to do is stick in the config directory, and Coldbox/WireBox will find it.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

The WireBox config struct in your ColdBox.cfc is actually optional. The default binder (AKA WireBox config) is config.wirebox. You really only need to specify it if you’re doing something other than the default. I’ve gotten to the point where I like to remove the unnecessary comments and config bits that aren’t actually doing something just to keep my ColdBox config nice and clean. I also keep the docs bookmarked so I can quickly look up settings if I need to add them back in :slight_smile:

Also, since you’re new to ColdBox you might find some value reading through our PDF ref cards. Start with the ColdBox Platform and WireBox Dependency Injection ones.
http://wiki.coldbox.org/wiki/Dashboard.cfm#PDF_Ref_Cards

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Those were the parts I was missing!

1 - I didn’t have a wirebox.cfc in my config directory
2 - When I declared it according to the docs (http://wiki.coldbox.org/wiki/ConfigurationCFC.cfm#wirebox), config.Wirebox wasn’t able to be located. That was solved firstly by just declaring it as wirebox, since coldbox and Wirebox are in the same directory. It was solved secondly by the post below, where the wirebox config is optional
3 - Once wirebox was found, I just added the mapDirectory(getAppMapping() & ".model) /> and it found my objects.

Question - is mapDirectory() automativcally recursive? I had in there mapDirectory(model), mapDirectory(model.user), and all of the other folders in there, and that configuration worked. I just removed the other entries, and just left mapDirectory(model), re-initialized the framework and it still works, so it appears that it is.

Thanks for the help!

Yes, mapDirectory is recursive. Note, you can still control much of how your objects are mapped via annotations on the objects themselves. For instance, putting “singleton” in the component declaration will tell WireBox to make that CFC a singleton.

component singleton {}

Also, note your code below will NOT work on Amazon since getAppMapping() be an empty string which will leave a leading dot in your path. That’s why I included the code snipped in the earlier E-mail that checked the length of the app mapping and created a prefix that was either blank or the mapping followed by a period.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com