[coldbox-4]: How to detect environment outside config

320 views
Skip to first unread message

Ancient Programmer

unread,
May 15, 2016, 8:51:52 AM5/15/16
to ColdBox Platform
Folks,

I was wondering if ColdBox has a built-in variable or method to determine which environment (development, staging, or production) the site is currently running. I would like to call the variable/method in controllers.

Thanks!

Tim Brown

unread,
May 15, 2016, 8:57:52 AM5/15/16
to col...@googlegroups.com
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/6ce49b7b-3aec-4371-854d-a22c7a03e379%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ancient Programmer

unread,
May 15, 2016, 12:24:48 PM5/15/16
to ColdBox Platform
Hi Tim,

Thanks for the reply.
But that specific method is only applied in ColdBox configuration. I'm looking for the one that I can call from controller.

Jon Clausen

unread,
May 15, 2016, 12:27:33 PM5/15/16
to col...@googlegroups.com

From a controller (or view), you would call #getSetting("environment")# to retrieve the current environment setting.

Jon

Andrew Scott

unread,
May 15, 2016, 12:48:55 PM5/15/16
to col...@googlegroups.com
What you could do, as I can't recall if the variable is exposed or if one is even available. Is to setup a variable yourself.

Then use the getSettings to read back and detect if it is production or not based on that variable.

In the past I used an interceptor to do this, to globally set a variable for my application.




Regards,
Andrew Scott


Ancient Programmer

unread,
May 17, 2016, 12:41:42 AM5/17/16
to ColdBox Platform
Thanks everyone!

In config/ColdBox.cfc - configure(), I defined settings.environment = "production"; AND in development(), I defined settings.environment = "development";
From controller or view, I can call getSetting("environment") to determine what environment I am now.

It worked!

br...@bradwood.com

unread,
May 17, 2016, 1:05:39 AM5/17/16
to col...@googlegroups.com
No, you don't need to manually set the "environment" setting, that's handled for you!  It defaults to production, and if one of your environment regex's are matched, then it automatically gets set to that environment name.  All you need to do is use it.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Ancient Programmer

unread,
May 18, 2016, 9:44:49 AM5/18/16
to ColdBox Platform
Hi Brad,

I knew that. But, my question was "how to determine environment outside the configuration file, such as from controllers or views."
I tested out. It turned out I don't need to define environment variable. I just call getSetting("environment"); from my controllers and magically it tells me in which environment my app is running. Beautiful...:)
Reply all
Reply to author
Forward
0 new messages