Instantiate Coldbox from sub directory

Hi guys,

I’ve been looking at this issue.
https://groups.google.com/forum/#!topic/railo/cSfxUj0TbvA

long story short, if you call coldbox from say a sub directory (steps to reproduce)

under your website root (same folder as application.cfc etc)
create a directory called crap, add an index.cfm
restart your server, call crap/index.cfm and you’ll get an error.
call the root index.cfm first coldbox initializes then call crap/index.cfm and it’ll load fine, well technically it loads index.cfm in the root which is fine.

my issue is I need to be able to initialize the application from a sub directory like crap/index.cfm but there is code for instance
in application.cfc

the reason I need to be able to initialize it from a sub directory is for my gateway to call it first, as have a gateway set to start automatically when the server starts. this of course goes mental as the application.cfc throws a mapping error.

what is the best way for me to fix this?
is it to hard code some root paths etc? or is their a coldbox way

cheers

ColdBox will guess the app mapping based on where the template lives that is being executed when the framework first initializes. 99% of the time, it’s going to be your root index.cfm. If you want to start up the app from another location, you need to specify the COLDBOX_APP_MAPPING and COLDBOX_CONFIG_FILE in Application.cfc.

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 your response.
the root is
http://localhost:8888/test/index.cfm

I call http://localhost:8888/test/crap/test/index.cfm

I have
(this is the root where my application.cfc is, so under it is /config etc)

this gets me a step further

invalid component definition, can’t find crap.test.config.Coldbox
Stacktrace The Error Occurred in
C:\webapps\test\coldbox\system\web\loader\CFCApplicationLoader.cfc: line 76
74:
75: //Create config Object
76: oConfig = createObject(“component”, configCreatePath);
77:
78: //Decorate It

is the COLDBOX_CONFIG_FILE just a cf component path “config.coldbox” ?

I also tried a mapping
<cfset this.mappings[’/crud’] = “C:\webapps\test”> (test being the root)

invalid component definition, can’t find crap/test.config.WireBox

The Error Occurred in
C:\webapps\test\coldbox\system\ioc\Injector.cfc: line 958
956: // Check if just a plain CFC path and build it
957: if( isSimpleValue(arguments.binder) ){
958: arguments.binder = createObject(“component”,arguments.binder);
959: }
960:

I know I’m doing something simple wrong

I’m going to hit the bed now, far too late here, so I won’t be replying for another 7 hours or so.

CHeers

Well, a mapping of config.Coldbox will only work if your config folder is in your web root or you had a mapping called config. Whatever you put there simply needs to be a full resolvable path to the config file. test.config.ColdBox should suffice.

Now regarding your WireBox error. ColdBox assumes your config file will be located in /config/WireBox.cfc and since it isn’t you’ll need to specify this in your ColdBox config to tell ColdBox where it is:

wirebox = {
binder = ‘test.config.WireBox’
};

I’m actually a little surprised the WireBox binder didn’t pick up the app mapping. We should probably look into that as a possible bug.

Now, I set up a test app that mimicked your folder structure and I had one last error that you may or may not run into. The error was that ColdBox couldn’t find any handlers defined in /test/crap/test/handlers/ I’m using the NON-inheritance approach for my Application.cfc and it turns out the COLDBOX_APP_MAPPING parameter was being left out of the “new Coldbox()” line in onApplicationStart. It needed to look like this:

public boolean function onApplicationStart(){
application.cbBootstrap = new Coldbox(COLDBOX_CONFIG_FILE,COLDBOX_APP_ROOT_PATH,COLDBOX_APP_KEY,COLDBOX_APP_MAPPING);
application.cbBootstrap.loadColdbox();
return true;
}

I’m not sure why my sample app was incorrect, but you might want to double check yours in case we have it wrong in an official location.

Oh, and here’s what I had in my Application.cfc too:

COLDBOX_APP_ROOT_PATH = expandPath("/test");
COLDBOX_APP_MAPPING = “test”;
COLDBOX_CONFIG_FILE = “test.config.ColdBox”;
COLDBOX_APP_KEY = “”;

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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