The configure() Method
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:
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.
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:
1
function configure(){
2
3
// parent settings
4
parentSettings = {
5
woot = "Module set it!"
6
};
7
8
// module settings - stored in the main configuration settings struct as modules.{moduleName}.settings
9
settings = {
10
display = "core"
11
};
12
13
// layout settings
14
layoutSettings = {
15
defaultLayout = "MyModuleLayout.cfm"
16
};
17
18
// Module Conventions
19
conventions = {
20
handlersLocation = "handlers",
21
viewsLocation = "views",
22
layoutsLocation = "layouts",
23
pluginsLocation = "plugins",
24
modelsLocation = "model"
25
};
26
27
// datasources
28
datasources = {
29
mysite = {name="mySite", dbType="mysql", username="root", password="root"}
30
};
31
32
// SES Routes
33
routes = [
34
// load the routes.cfm in the config folder of the module
35
"config/routes",
36
// explicit route declared here
37
{pattern="/api-docs", handler="api",action="index"}
38
];
39
40
// Interceptor Config
41
interceptorSettings = {
42
customInterceptionPoints = "onModuleError"
43
};
44
interceptors = [
45
{name="modulesecurity",class="#moduleMapping#.interceptors.ModuleSecurity",
46
properties={
47
URLMatch = '/api-docs',
48
loginURL = '/api-docs/login'
49
}
50
];
51
52
// binder mappings
53
binder.map("MyModuleService").to("#moduleMapping#.model.ModuleService");
54
// or easy map entire directory
55
binder.mapDirectory("#moduleMapping#.model");
56
}
Copied!
Last modified 3yr ago
Copy link
Edit on GitHub