[ColdBox 4.1] Best way to reach the COLDBOX_APP_ROOT_PATH

I’m curious to know if the following is the official way to grab the COLDBOX_APP_ROOT_PATH or is it only an alternative to an official solution?
I found how to get to it by dumping application, so I’m not sure if I really should be grabbing it the following way since I have also noticed the root path in various other places within the application scope as well.

application.cbbootstrap.getColdbox_app_root_path()

Thank you for your time and expertise!
Ryan Hinton

You just need the app root?

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057
Direct: (909) 248-3408

ColdBox Platform: http://www.coldbox.org

ContentBox Platform: http://www.gocontentbox.org
Linked In: http://www.linkedin.com/pub/3/731/483

Social: twitter.com/ortussolutions | twitter.com/coldbox | twitter.com/lmajano | twitter.com/gocontentbox

Hi Luis!

Yes, I need exactly what the COLDBOX_APP_ROOT_PATH gives me. I just want to make sure that I am utilizing the correct method and/or scopes to properly retrieve it.
I noticed there are a couple places in which I can retrieve the path out of the application scope:
writeDump(var=application.cbbootstrap.getColdbox_app_root_path());
writeDump(var=application.cbcontroller.getAppRootPath());
writeDump(var=application.cbcontroller.getConfigSettings().applicationPath);
writeDump(var=application.cbcontroller.getColdboxSettings().applicationPath);

Thank you,
Ryan

Can you back up and tell us what you’re trying to accomplish? I’ve never needed that value before inside my actual application. It’s just a setting to tell the ColdBox bootstrap how to load.

Once you’re in your apap, getSetting( “appMapping” ) should tell you where the site lives in regards to the web root.

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!

I have an API module with a “create” method that is writing a file and I am attempting to use the COLDBOX_APP_ROOT_PATH that I found in the root application.cfc to dynamically give me the root path so it is not me hard coding it, in case we move the web app around, etc.

I just figured out “I think” how you are using getSetting(). I noticed there is an empty “settings” struct in the Coldbox.cfc, so I placed a test in there called “appMap” = “here” and I was able to retrieve it with getSetting(“appMap”)
I can use this and that would be fine, but if the root path is already instantiated somewhere else for me, why would I need to sort of re-invent the wheel by placing it here? I can only think that if you guys obit COLDBOX_APP_ROOT_PATH in the future, then part of my app would stop working, of course. So maybe this is your reason for me to utilize getSetting() instead?

I hope you are doing well, Brad!

Thank you,
Ryan

There’s no need to manually create the setting, ColdBox does all that for you. Dump this out in a view to see it:

#getSetting( “appMapping” )#

I was going off memory in my first post and didn’t type the full setting name. This setting is generated dynamically by ColdBox when it loads up.

My personal preference is not to use appMapping, but rather create a CF mapping in this.mappings in your Application.cfc that points to the folder you want to use.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

I did try exactly that and you had it correct in your original post, but it returned an empty string, which got me to start hunting down where I could set it which the I found the Coldbox.cfc’s setting struct.

It is returning an empty string because I am in a Module?

Thank you,
Ryan

If it returns an empty string, that means the ColdBox site is in the web root. So basically expandPath( ‘/’ ) would point to the root of your site. appmapping is relative to the web root.

If that isn’t what you expected can you show us your directory structure?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

That would be correct, Brad. My ColdBox is in the web root.

However, I need the actual path like so, F:\websites\webapp1. expandPath(’/’) does work like you mentioned. I was only wanting to reuse instantiated objects or variables wherever possible. Since the path has already been created and stored by ColdBox, I figured it would be better than to create another instance of a variable or method of the same path. Do you suggest that I not reuse what is available in this case?

Thank you,
Ryan

I don’t understand what the issue is with using the appMapping setting.

expandPath( ‘/’ & getSetting( “appmapping” ) )

should always give you the canonical path to your ColdBox root.

If you are not wanting to do the expand path every time, just use this:

getSetting( ‘applicationPath’, true )

To see a list of all the framework settings, you can dump this:

getSettingStructure()

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,

I like the getSetting( ‘applicationPath’, true ). Thank you. :slight_smile: BTW, what does the second param do?

Responding to your question:
It is only the fact that when I know something exists in memory, then I prefer to use what is already there in memory rather than calling a method (in this case something like expandPath) to produce more processing and/or rendering time to recreate what already exists. It’s negligible and a nonfactor in the broad spectrum of things I know, but I do the best I can at keeping the processing and rendering time as efficient as possible, even if there is not a noticeable difference. It’s peace of mind at that moment, because then I think of what happens if the servers get bogged down for whatever reason and/or the network slows down or someone is still using a 56K modem (lol).

Without knowing the inner-workings of ColdBox, I am wondering why there are so many places where the app root path is stored in application scope memory instead of only one place. I am sure there are logical reasons that I cannot think of, which I can only think that it is moreso of a convenience factor, so I was not even going to bother to ask because of my inferior knowledge of ColdBox, but I have somehow come to this question anyway. lol

BTW, I understand there has to be some give and take to processing to help ease our development world by using OO and frameworks and the likes which is all again another convenience factor, but I still try to help out memory and processing where possible by attempting to keep things tightied up and reusable and following the D.R.Y. methodology as much as possible.

Thank you for you help guys! You guys are the best! :slight_smile:
Ryan

> BTW, what does the second param do?

Check out the code or the API docs :slight_smile:

http://apidocs.ortussolutions.com/coldbox/4.0.0/coldbox/system/FrameworkSupertype.html#getSetting()

The second param is the FWSetting flag. ColdBox basically has framework and user settings internally. appMapping should probably be a fw setting, but it USED to be configurable in the config file back in the day so it was historically a user setting.

> It is only the fact that when I know something exists in memory, then I prefer to use what is already there in memory rather than calling a method

No worries then. My confusion was that I thought you were saying it wouldn’t work, not that you just wanted a different way.

I am wondering why there are so many places where the app root path is stored in application scope memory

How many places are you seeing it? The Application.cfc setting is just a hint to the bootstrap code and is only needed if you have ColdBox in a subfolder AND are using a proxy. As far as I know, once you get into the framework settings, each setting has a unique use and purpose. I’d be interested to see if we have more than one setting containing the exact same thing. They’re all created dynamically when the framework boots up so it’s not really like we’re doing work twice since all the stored paths are based off the root application path.

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,

It very well could be good purposes for every one of these places found. It’s just a curiosity.

All of the following plus the various ways of getSetting()
writeDump(var=application.cbbootstrap.getColdbox_app_root_path());

writeDump(var=application.cbcontroller.getAppRootPath());
writeDump(var=application.cbcontroller.getConfigSettings().applicationPath);
writeDump(var=application.cbcontroller.getColdboxSettings().applicationPath);

Thank you,
Ryan

The bootstrap is the superclass for your Application.cfc (if using inheritance) so it’s the ground floor where you can tell ColdBox where the app lives (not required in most apps).
The property in the controller is the where the setting lives while the framework is booting up (before settings have even been created or config parsed)
Once the framework is up, the app path is injected into both setting structs for convenience.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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