Module Layout
In order to create a module you must first create a nicely named directory within the modules conventions directory. For example, let's build a simple hello world module. CommandBox to the rescue!
1
coldbox create module helloworld
Copied!
Here is the output:
1
Created /Users/lmajano/tmp/myapp/modules_app/helloworld
2
Created /Users/lmajano/tmp/myapp/modules_app/helloworld/handlers
3
Created /Users/lmajano/tmp/myapp/modules_app/helloworld/handlers/Home.cfc
4
Created /Users/lmajano/tmp/myapp/modules_app/helloworld/models
5
Created /Users/lmajano/tmp/myapp/modules_app/helloworld/models/models_here.txt
6
Created /Users/lmajano/tmp/myapp/modules_app/helloworld/ModuleConfig.cfc
7
Created /Users/lmajano/tmp/myapp/modules_app/helloworld/views
8
Created /Users/lmajano/tmp/myapp/modules_app/helloworld/views/home
9
Created /Users/lmajano/tmp/myapp/modules_app/helloworld/views/home/index.cfm
Copied!
The layout of a ColdBox Module is optional except for one file: ModuleConfig.cfc. This is a simple CFC that boots up your module and tells the host application how your module is loaded, unloaded and behaves. If you are leveraging CommandBox then you can also declare a box.json for the module itself in order to declare dependencies and development dependencies for it.
Below are all the possible combinations of a module layout, you will notice that it is EXACTLY the same as a ColdBox application.
1
+Modules_app
2
+ {ModuleName - Unique}
3
+ ModuleConfig.cfc (The module configuration object Mandatory)
4
+ box.json (optional - if using CommandBox)
5
+ handlers (optional)
6
+ layouts (optional)
7
+ views (optional)
8
+ interceptors (optional)
9
+ models (optional)
Copied!
As you can see, the only mandatory resources for a module is the directory name in which it lives and a ModuleConfig.cfc. The module developer can choose to implement a simple module or a very complex module. All folders are optional and only what is used will be loaded. Not only are modules reusable and extensible, but you can easily create a module with dual functionality: A standalone application or a module. This is true reusability and flexibility. I don't know about you, but this is really exciting (Geek Alert!).
Copy link