[Coldbox 4.1] Application Setup


Please be patient with me, I am a new ColdBox user. Some concepts used here are new and foreign to me, so if you point me at the good examples or direct me to the appropriate documentation, I can probably pick up what I need. Most of my background in CF using frameworks. was using Fusebox.

I am in the process of trying to build a new ColdBox application with Chad Baloga, who is also on the forums; we both are tackling different issues in creating the app.

In an effort to handle a fairly complex navigation system that the app requires, I am building a navigation object, that will handle it.

I had intended to set it up so that the base object was an interface that is instantiated when the app is fired up.

I would have done this simply as a

application.nav = new models.m_navigation();

then, to configure the navigation, I would execute the methods to do whatever they need to do…

application.navigation.addNavBar(‘adminNavbar’,{type=‘tabs’,id= ‘navbar1’,ul_class = ‘nav nav-tabs’,class = ‘’});
application.navigation.addNavBar(‘userNavbar’,{type=‘tabs’,id= ‘navbar2’,ul_class = ‘nav nav-tabs’,class = ‘’});

and so on.

Ultimately, the idea would be to call a method later, say in a view or a layout file, to display the navigation, rendered where needs to be, however it needed to look:


I have been trying to figure out how I would accomplish the same thing in ColdBox, without leaving it as just a plain ole application variable, which has it’s own problems… mainly, the fact that fwreiniting doesnt reload the application var i created in the first place. I know there is a way to trigger events with fwreinit, and maybe that’s the simple answer here.

I tried it in Wirebox, and the main loading I can do… and works fine. But, after it’s in Wirebox, setup, say like this:


I could figure out how to inject it into the handlers:

But, I couldn’t figure out how I do the step between the instantiation at the beginning, and the first use of it… where it triggers the sequence of steps it needs to actually set it up before I use it the first time.

I looked at using it as a module… I actually set it up in a requestDecorator to add the module to the PRC, so I can refer to it in my views.

So, I thought I would trigger the setup sequence in the moduleConfig. I emulated the way the cbscrf and cbdebuger modules are setup; they both call a parseParentSettings function, so I did the same thing:

private function parseParentSettings(){

var oConfig = controller.getSetting( “ColdBoxConfig” );
var configStruct = controller.getConfigSettings();
var navigation = oConfig.getPropertyMixin( “navigation”, “variables”, structnew() );

configStruct.navigation = new models.m_navigation();
include “models\navdocs\default.cfm”;

// Incorporate settings
structAppend( configStruct.navigation, navigation, true );

Where the include loads the configuration file up.

However, after the module is configured and the system loads up, when I go to access the module, it returns empty structures… as if it wasn’t configured at all.

What am I missing?? Please tell me there is some obvious thing I am just overlooking…

If you read all that… THANKS.

Robert Bartlett

onDIComplete from the bottom of http://wiki.coldbox.org/wiki/Interceptors:Autowire.cfm#1._Configure_the_interceptor

**<cffunction** name="onDIComplete" access="public" returntype="void" output="false">
	<---  Call Anything to configure this object --->
	**<cfset** setRoles( getUserService().getAllRoles() )>
	**<cfset** validateAllRoles()>

Hi Robert, welcome to ColdBox! I would say let’s back away from the modules and parent settings stuff for now-- you’re just muddying the water I think.

When WireBox creates objects via getInstance(), this order is important (This is what Andrew Scott was talking about):

  1. CFC Created
  2. init() called
  3. Dependencies injected
  4. onDIComplete() called
  5. CFC returned

So, if you want your CFC to be a singleton, simply place the “singleton” annotation in the component declaration.

component singletion {}

So now, you want to set some data into this CFC when the app starts up. You have many options, and WireBox will easily allow all of them.

  1. If the data is just static, simply call the setters in your CFC’s init()
  2. If the data requires other CFC’s, call the setters in your onDIComplete()
  3. If you wish to set this data outside of the CFC itself, I would recommend using an interception point such as afterConfigurationLoad

My advice would to stop thinking about when to configure CFCs in relation to when they are created, and instead think about them in the overall application lifecycle. Let WireBox worry about creating and persisting components for you.



ColdBox Platform Evangelist
Ortus Solutions, Corp

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