Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
If you are using per-environment control in your parent application via the ColdBox.cfc
, you can also use that in your Module Configuration object. So the same conventions that are used in the parent configuration can be used in the module; having the name of the environment match a method name in your module config. So if the following environments are declared in your parent configuration file and the dev environment is detected, the dev()
method is called in your configuration object:
But if you declare that dev()
method in your Module Configuration object, it will be called as well after your configure()
method is called:
Modules configurations are stored in the host parent configuration structure under a modules
key according to their name. To retrieve them you can do
getModuleSettings( module )
: Returns the structure of module settings by the module name.
getModuleConfig( module )
: Returns the module's configuration structure
You can also use our injection DSL to inject module settings and configurations:
The injection DSL pattern is the following:
coldbox:setting:mySetting@module
: You can now inject easily a module setting by using the @module directive.
coldbox:moduleSettings:{module}
: You can now inject the entire module settings structure
coldbox:moduleConfig:{module}
: You can now inject the entire module configuration structure
If you have parseParentSettings
set to true in your ModuleConfig.cfc
(which is the default), ColdBox will look for a struct inside the moduleSettings
struct of your config/ColdBox.cfc
with a key equal to your module's this.modelNamespace
(default is the module name) and merge them with your modules settings
struct (as defined in your module's configure()
method) with the parent settings overwritting the module settings. This allows a user of your module to easily overwrite specific settings for their needs.
If parseParentSettings
is set to false
, your module's settings
will instead overwrite the settings set in the same moduleSettings
struct.
ModuleConfig.cfc
If you want to use the overridden settings in your ModuleConfig.cfc
, you will need to use it in the postModuleLoad
interceptor. Remember, all your modules register the ModuleConfig.cfc
as an interceptor, so all you need to do is add the postModuleLoad
function and you're off!
The module configuration object: ModuleConfig.cfc
is the boot code of your module and where you can tell the host application how this module will behave. This component is a simple CFC, no inheritance needed, because it is decorated with methods and variables by ColdBox at runtime.
The only requirement is that this object MUST exist in the root of the module folder and contain a configure()
method. This is the way modules are discovered, so if there is no ModuleConfig.cfc
in the root of that folder inside of the modules folder, the framework skips it. So let's investigate what we need or can do in this component.
The module configuration object is also treated as an Interceptor once it is created and configured.
There are two life-cycle callback events you can declare in your ModuleConfig.cfc
:
onLoad()
: Called when the module is loaded and activated
onUnLoad()
: Called when the module is unloaded from memory
This gives you great hooks for you to do bootup and shutdown commands for this specific module. You can build a ContentBox or Wordpress like application very easily all built in to the developing platform.
Also, remember that the configuration object itself is an interceptor so you can declare all of the framework's interception points in the configuration object and they will be registered as interceptors.
This is a powerful feature, you can create an entire module based on a single CFC and just treat it as an interceptor. So get your brain into gear and let the gas run, you are going for a ride baby!
Once the public properties are set, we are now ready to configure our module. You will do this by creating a simple method called configure()
and adding variables to the following configuration structures:
It is important to note that there is only ONE running application and the modules basically leach on to it. So the following structures will append their contents into the running application settings: parentSettings, datasources, webservices, customInterceptionPoints and interceptors.
All of the configuration settings that are declared in your configuration object will be added to a key in the host application settings called modules. Inside of this structure all module configurations will be stored according to their module name and remember that the module name comes from the name of the directory on disk. So if you have a module called helloworld then the settings will be stored in the following location: ConfigSettings.modules.helloworld
Below is an example of some settings:
Here is a listing of all public properties that can be defined in a module.
Below you can see an example of declarations for the configuration object:
At runtime, the configuration object will be created by ColdBox and decorated with the following private properties (available in the variables
scope):
You can use any of these private variables to create module settings, load CFCs, add binder mappings, etc.
Property
Type
Description
parentSettings
struct
Settings that will be appended and override the host application settings
settings
struct
Custom module settings that will only be available to the module. If parseParentSettings
is set to true (default), then settings from config/Coldbox.cfc
for this module will be merged with these settings. (Think of these as default settings in that case.) Please see the retrieving settings section
conventions
struct
A structure that explains the layout of the handlers, plugins, layouts and views of this module.
datasources
struct
A structure of datasource metadata that will append and override the host application datasources configuration
interceptorSettings
struct
A structure of settings for interceptor interactivity which includes the following sub-keys:
interceptors
array of structs
An array of declared interceptor structures that should be loaded in the entire application. Follows the same pattern as the ConfigurationCFC interceptor declarations.
layoutSettings
struct
A structure of elements that setup layout configuration data for the module with the following keys:
routes
array
An array of declared URL routes or locations of routes for this module. The keys of the structure are the same as the addRoute() method of the SES interceptor or a simple string location to the routes file to include.
wirebox
struct
A structure of WireBox configuration data, please refer to the [WireBox Configuration](http://wiki.coldbox.org/wiki/WireBox.cfm#Configure()_method) area or just use the injected binder object for mappings.
Property
Type
Required
Default
Description
title
string
false
---
The title of the module
author
string
false
---
The author of the module
webURL
string
false
---
The web URL associated with this module. Maybe for documentation, blog, links, etc.
description
string
false
---
A short description about the module
version
string
false
---
The version of the module
viewParentLookup
boolean
false
true
If true, coldbox checks for views in the parent overrides first, then in the module. If false, coldbox checks for views in the module first, then the parent.
layoutParentLookup
boolean
false
true
If true, coldbox checks for layouts in the parent overrides first, then in the module. If false, coldbox checks for layouts in the module first, then the parent.
entryPoint
route
false
---
The module's default route (ex:/forgebox
) that ColdBox will use to create an entry point pattern link into the module. Similar to the default event setting. The SES interceptor will also use this to auto-register the module's routes if used by calling the method addModuleRoutes()
for you.
inheritEntryPoint
boolean
false
false
If true, then the entrypoint
will be constructed by looking at its parent hierarchy chain. This is a great way to build automated nesting schemas for APIs
activate
boolean
false
true
You can tell ColdBox to register the module but NOT to activate it. By default, all modules activate.
parseParentSettings
boolean
false
true
If true, ColdBox will merge any settings found in moduleSettings[ this.modelNamespace ]
in the config/ColdBox.cfc
file with the module settings, overriding them where the keys are the same. Otherwise, settings in the module will override the parent configuration.
aliases
array
false
[]
An array of names that can be used to execute the module instead of only the module folder name
autoMapModels
boolean
false
true
Will automatically map all model objects under the models folder in WireBox using @modulename
as part of the alias.
autoProcessModels
boolean
false
false
If false, then all models will not be processed by WireBox metadata to improve performance. If true, then all object models will be inspected for metadata which can be time consuming.
cfmapping
string
false
empty
The ColdFusion mapping that should be registered for you that points to the root of the module.
disabled
boolean
false
false
You can manually disable a module from loading and registering
dependencies
array
false
[]
An array of dependent module names. All dependencies will be registered and activated FIRST before the module declaring them.
modelNamespace
string
false
moduleName
The name of the namespace to use when registering models in WireBox. By default it uses the name of the module.
applicationHelper
array
false
[]
An array of files from the module to load as application helper UDF mixins
Property
Description
appMapping
The appMapping
setting of the current host application
binder
The WireBox configuration binder object
cachebox
A reference to CacheBox
controller
A reference to the application's ColdBox Controller
log
A pre-configured LogBox Logger object for this specific class object (coldbox.system.logging.Logger
)
logBox
A Reference to LogBox
moduleMapping
The moduleMapping
setting of the current module. This is the path needed in order to instantiate CFCs in the module.
modulePath
The absolute path to the current loading module
wirebox
A Reference to WireBox