Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The basic configuration object has 1 method for application configuration called configure()
where you will place all your configuration directives and settings:
Inside of this configuration method you will place several core and third-party configuration structures that can alter your application settings and behavior. Below are the core directives you can define:
The configuration CFC has embedded environment control and detection built-in. In this structure you will set up the application environments and their associated regular expressions for its cgi
host names to match for you automatically. If the framework matches the regex with the associated cgi.http_host
, it will set a setting called Environment
in your configuration settings and look for that environment setting name in your CFC as a method by convention. That's right, it will check if your CFC has a method with the same name as the environment and if it exists, it will call it for you. Here is where you basically override, remove, or add any settings according to your environment.
Warning : The environment detection occurs AFTER the
configure()
method is called. Therefore, whatever settings or configurations you have on theconfigure()
method will be stored first, treat those as Production settings.
In the above example, I declare a development key with a value list of regular expressions. If I am in a host that starts with cf2016, this will match and set the environment setting equal to development. It will then look for a development method in this CFC and execute it.
If you want your own detection algorithm instead of looking at the cgi.http_host
variable, then fear not. You will NOT fill out an environments structure but actually create a method with the following signature:
This method will be executed for you at startup and it must return the name of the environment the application is on. It will then store it and execute the method if it exists.
In order to create a ColdBox application you must adhere to some naming conventions and a pre-set directory structure. This is needed in order for ColdBox to find what it needs and to help you find modules more easily instead of configuring every single area of your application.
ColdBox relies on conventions instead of configurations.
You can also configure many aspects of ColdBox, third-party modules and application settings in our programmtic configuration object: ColdBox.cfc
.
Please note that anytime you make any configuration changes or there are things in memory you wish to clear out, you will be using a URL action that will tell the ColdBox to reinitialize the application. This special URL variable is called fwreinit
and can be any value or a specific password you setup in the .
You can also use CommandBox to reinit your application if you are using its embedded server:
This element defines custom conventions for your application. By default, the framework has a default set of conventions that you need to adhere too. However, if you would like to implement your own conventions for a specific application, you can use this setting, otherwise do not declare it:
The ColdBox configuration CFC is the heart of your ColdBox application. It contains the initialization variables for your application and extra information used by third-party modules and ultimately how your application boots up. In itself, it is also an event listener or , so it can listen to life-cycle events of your application.
This CFC is instantiated by ColdBox and decorated at runtime so you can take advantage of some dependencies.
Controller : Reference to the main ColdBox Controller object (coldbox.system.web.Controller
)
AppMapping : The location of the application on the web server
LogBoxConfig : A reference to a LogBox configuration object
Once the application starts up, a reference to the instantiated configuration CFC will be stored in the configuration settings with the key coldboxConfig
. You can then retrieve it later in your handlers, interceptors, modules, etc.
Note that the config CFC does not have the same variables mixed into it that a "normal" interceptor has. You can still access everything you need, but will need to get it from the controller
in the variables scope.
The ColdBox directive is where you configure the framework for operation.
Info : Please note that there are no mandatory settings as of ColdBox 4.2.0. If fact, you can remove the config file completely and your app will run. It will be impossible to reinit the app however without a reinit password set.
reinitPassword
Protect the reinitialization of the framework URL actions. For security, if this setting is omitted, we will create a random password. Setting it to an empty string will allow you to reinitialize without a password. Always have a password set for public-facing sites.
handlersIndexAutoReload
Will scan the conventions directory for new handler CFCs on each request if activated. Use false for production, this is only a development true setting.
These settings map 1-1 from ColdBox events to the Application.cfc
life-cycle methods. The only one that is not is the defaultEvent
, which selects what event the framework will execute when no incoming event is detected via URL/FORM or REMOTE executions.
The ColdBox extension points are a great way to create federated applications that can reuse a centralized core instead of the local conventions. It is also a great way to extend some core classes with your own.
applicationHelper
A list or array of absolute or relative paths to a UDF helper file. The framework will load all the methods found in this helper file globally. Meaning it will be injected in ALL handlers, layouts and views.
viewsHelper
A list or array of absolute or relative paths to a UDF helper file. The framework will load all the methods found in this helper in layouts and views only.
modulesExternalLocation
A list or array of locations of where ColdBox should look for modules to load into your application. The path can be a cf mapping or cfinclude
compatible location. Modules are searched and loaded in the order of the declared locations. The first location ColdBox will search for modules is the conventions folder modules
viewsExternalLocation
The CF include path of where to look for secondary views for your application. Secondary views look just like normal views except the framework looks in the conventions folder first and if not found then searches this location.
layoutsExternalLocation
The CF include path of where to look for secondary layouts for your application. Secondary layouts look just like normal layouts except the framework looks in the conventions folder first and if not found then searches this location.
handlersExternalLocation The CF dot notation path of where to look for secondary events for your application. Secondary events look just like normal events except the framework looks in the conventions folder first and if not found then searches this location.
requestContextDecorator The CF dot notation path of the CFC that will decorate the system Request Context object.
controllerDecorator The CF dot notation path of the CFC that will decorate the system Controller
exceptionHandler
The event handler to call whenever ANY non-catched exception occurs anywhere in the request lifecycle execution. Before this event is fired, the framework will log the error and place the exception in the prc as prc.exception
.
invalidHTTPMethodHandler
The event handler to call whenever a route or event is accessed with an invalid HTTP method.
invalidEventHandler
This is the event handler that will fire masking a non-existent event that gets requested. This is a great place to place 302 or 404 redirects whenever non-existent events are being requested.
customErrorTemplate
The relative path from the application's root level of where the custom error template exists. This template receives a key in the private request collection called exception
that contains the exception. By default ColdBox does not show robust exceptions, you can turn on robust exceptions by choosing the following template:
handlerCaching
This is useful to be set to false in development and true in production. This tells the framework to cache your event handler objects as singletons.
eventCaching
This directive tells ColdBox that when events are executed they will be inspected for caching metadata. This does not mean that ALL events WILL be cached if this setting is turned on. It just activates the inspection mechanisms for whenever you annotate events for caching or using the runEvent()
caching methods.
viewCaching
This directive tells ColdBox that when views are rendered, the cache=true
parameter will be obeyed. Turning on this setting will not cause any views to be cached unless you are also passing in the caching parameters to your renderView()
or event.setView()
calls.
proxyReturnCollection
This is a boolean setting used when calling the ColdBox proxy's process()
method from a Flex or SOAP/REST call. If this setting is set to true, the proxy will return back to the remote call the entire request collection structure ALWAYS! If set to false, it will return, whatever the event handler returned back. Our best practice is to always have this false and return appropriate data back.
implicitViews
Allows you to use implicit views in your application and view dispatching. You can get a performance boost if you disable this setting.
caseSensitiveImplicitViews
By default implicit views are case sensitive since ColdBox version 5.2.0, before this version the default was false.
The CacheBox structure is based on the , and it allows you to customize the caches in your application. Below are the main keys you can fill out, but we recommend you review the CacheBox documentation for further detail.
Info : We would recommend you create a
config/CacheBox.cfc
and put all your caching configuration there instead of in the main ColdBox configuration file. This will give you further portability and decoupling.
An absolute or relative path to the CacheBox configuration CFC or XML file to use instead of declaring the rest of the keys in this structure. So if you do not define a cacheBox structure, the framework will look for the default value: config/CacheBox.cfc
and it will load it if found. If not found, it will use the default CacheBox configuration found in /coldbox/system/web/config/CacheBox.cfc
A structure that enables scope registration of the CacheBox factory in either server, cluster, application or session scope.
The configuration of the default cache which will have an implicit name of default which is a reserved cache name. It also has a default provider of CacheBox which cannot be changed.
A structure where you can create more named caches for usage in your CacheBox factory.
Another cool concept for the Configuration CFC is that it is also registered as a once the application starts up automatically for you. Create functions that will listen to application events:
Directive
Type
Description
struct
An optional structure used to configure CacheBox. If not setup the framework will use its default configuration found in /coldbox/system/web/config/CacheBox.cfc
struct
The main coldbox directives structure that holds all the coldbox settings.
struct
A structure where you will configure the application convention names
struct
A structure where you will configure environment detection patterns
struct
A structure where you will configure the FlashRAM
struct
An optional structure to configure application wide interceptor behavior
array
An optional array of interceptor declarations for your application
struct
A structure where you define how the layout manager behaves in your application
array
An array of layout declarations for implicit layout-view-folder pairings in your application
struct
An optional structure to configure the logging and messaging in your application via LogBox
struct
An optional structure to configure application wide module behavior
struct
An optional structure to configure individual modules installed in your application.
struct
A structure where you can put your own application settings
struct
An optional structure used to define how WireBox is loaded
The layouts array element is used to define implicit associations between layouts and views/folders, this does not mean that you need to register ALL your layouts. This is a convenience for pairing them, we are in a conventions framework remember.
Before any renderings occur or lookups, the framework will check this array of associations to try and match in what layout a view should be rendered in. It is also used to create aliases for layouts so you can use aliases in your code instead of the real file name and locations.
The logBox structure is based on the LogBox declaration DSL, see the LogBox Documentation for much more information.
Info : If you do not define a logBox DSL structure, the framework will look for the default configuration file
config/LogBox.cfc
. If it does not find it, then it will use the framework's default logging settings.
ConfigFile
You can use a configuration CFC instead of inline configuration by using this setting. The default value is config/LogBox.cfc
, so by convention you can just use that location. If no values are defined or no config file exists, the default configuration file is coldbox/system/web/config/LogBox.cfc
.
This is an array of interceptor definitions that you will use to register in your application. The key about this array is that ORDER matters. The interceptors will fire in the order that you register them whenever their interception points are announced, so please watch out for this caveat. Each array element is a structure that describes what interceptor to register.
Warning : Important: Order of declaration matters! Also, when declaring multiple instances of the same CFC (interceptor), make sure you use the name attribute in order to distinguish them. If not, only one will be registered (the last one declared).
This structure configures the interceptor service in your application.
throwOnInvalidStates
This tells the interceptor service to throw an exception if the state announced for interception is not valid or does not exist. Defaults to false.
customInterceptionPoints
This key is a comma delimited list or an array of custom interception points you will be registering for custom announcements in your application. This is the way to provide an observer-observable pattern to your applications.
Info Please see the Interceptors section for more information.
This directive is how you will configure the Flash RAM for operation. Below are the configuration keys and their defaults:
This structure allows you to define a system-wide default layout and view.
Hint Please remember that the default layout is
Main.cfm
These are custom application settings that you can leverage in your application.
You can read our Using Settings section to discover how to use all the settings in your application.
The modules structure is used to configure the behavior of the .
Danger Please be very careful when using the
autoReload
flag as module routing can be impaird and thread consistency will also suffer. This is PURELY a development flag that you can use at your own risk.
ColdBox makes it easy to access the configuration stored in your Java system properties and your server's environment variables, even if you don't know which one it is in! Three methods are provided for your convenience:
config/ColdBox.cfc
or a ModuleConfig.cfc
If you are inside config/ColdBox.cfc
or a ModuleConfig.cfc
or a config/WireBox.cfc
you can use the three system settings functions directly! No additional work required.
Application.cfc
If you would like to access these methods in your Application.cfc
, create an instance of coldbox.system.core.util.Util
and access them off of that component. This is required when adding a datasource from environment variables.
Example:
The ColdBox Controller (stored in ColdFusion application
scope) stores all your application settings and also your system settings:
ColdboxSettings : Framework specific system settings
ConfigSettings : Your application settings
You can use the following methods to retrieve/set/validate settings in your handlers/layouts/views and interceptors:
You can also get access to these methods via the ColdBox Controller component:
You can use the WireBox injection DSL to inject settings in your models or non-coldbox objects. Below are the available DSL notations:
coldbox:setting:{key}
: Inject a specified config setting key
coldbox:fwsetting:{key}
: Inject a specified system setting key
coldbox:configSettings
: Inject a reference to the application settings structure
coldbox:fwSettings
: Inject a reference to the ColdBox System settings structure
This configuration structure is used to configure the dependency injection framework embedded in ColdBox.
binder
The location of the WireBox configuration binder to use for the application. If empty, we will use the binder in the config
folder called by conventions: WireBox.cfc
singletonReload
A great flag for development. If enabled, WireBox will flush its singleton objects on every request so you can develop without any headaches of reloading.
Warning : This operation can cause some thread issues and it is only meant for development. Use at your own risk.
This structure is used to house module configurations. Please refer to each module's documentation on how to create the configuration structures. Usually the keys will match the name of the module to be configured.
If you need to access these configuration values in other components, consider adding the values to your and injecting the values into your other components
Name | Arguments | Description |
|
| Looks for |
|
| Returns the Java System property for |
|
| Returns the server environment variable for |
The Application.cfc
is one of the most important files in your application as it is where you define all the implicit ColdFusion engine events, session, client scopes, ORM, etc. It is also how you tell ColdFusion to bootstrap the ColdBox Platform for your application. There are two ways to bootstrap your application:
Leverage composition and bootstrap ColdBox (Default)
Leverage inheritance and bootstrap ColdBox
The composition approach allows you to have a more flexible configuration as it will allow you to use per-application mappings for the location of the ColdBox Platform.
Tip: To see the difference, just open the appropriate Application.cfc
in the application templates.
You can set some variables in the Application.cfc
that can alter Bootstrapping conditions:
The Boostrapper also leverages a default locking timeout of 30 seconds when doing loading operations. You can modify this timeout by calling the setLockTimeout()
method on the Bootsrapper object.
Variable
Default
Description
COLDBOX_APP_ROOT_PATH
App Directory
Automatically set for you. This path tells the framework what is the base root location of your application and where it should start looking for all the agreed upon conventions. You usualy will never change this, but you can.
COLDBOX_APP_MAPPING
/
The application mapping is ESSENTIAL when dealing with Flex or Remote (SOAP) applications. This is the location of the application from the root of the web root. So if your app is at the root, leave this setting blank. If your application is embedded in a sub-folder like MyApp, then this setting will be auto-calculated to /MyApp
.
COLDBOX_CONFIG_FILE
config/ColdBox.cfc
The absolute or relative path to the configuration CFC file to load. This bypasses the conventions and uses the configuration file of your choice.
COLDBOX_APP_KEY
cbController
The name of the key the framework will store the application controller under in the application scope.