[Coldbox 4.1.0] ApplicationHelper for Modules?

Hi All,

Is there a way to do applicationHelper/includeUDF specific for a module? I have been looking around for a solution to this but couldn’t find anything. My modules will be acting like separate sub-apps and will have slightly different logic between them.

Thanks.
Brett

Alright, I think I might have figures this out. In the ModuleConfig.cfc I can do:

component{ function configure(){ parentSettings = { applicationHelper = ["myModulesApplicationHelper.cfm"] } } }

No there isn’t. Modules are, for the most part, assimilated into the parent app. This means any application helpers that a module contributes apply to the entire app. If you have more than one module with application helpers who include functions of the same name, you’d probably get a compilation error about defining the same UDF twice.

If you want to make your UDF behave differently based on what event is being run, that information should be available in the request context.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

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

This just registers your helper in the parent app. Also be careful, that might be overwriting any existing setting you already have in place.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

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

Brad,

Yes good advice. I did suspect that if I had ‘function1()’ as method in the application’s applicationHelper file and then had ‘function1()’ as method in my Modules applicationHelper I would run into problems. I should be ok though if I have ‘function1()’ in moduleA’s applicationHelper and ‘function1()’ in moduleB’'s applicationHelper, yes? At least it seems to work that way.

Thanks,
Brett

There is only a single setting for application helpers in a Coldbox app. It does not track helpers individually for each module. When a module is loaded, your helpers are added to the global list. You’re likely not noticing the issue because you’re incorrectly overwriting the entire array instead of appending.

Look at this example in cbi18n

https://github.com/ColdBox/cbox-i18n/blob/development/modules/cbi18n/ModuleConfig.cfc#L33

Also note, it’s the responsibility of your module to clean up after itself on unload as well:

https://github.com/ColdBox/cbox-i18n/blob/development/modules/cbi18n/ModuleConfig.cfc#L51-L61

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

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

Good stuff. Thanks, Brad.