A certain variable in each action for an entire module

Is there a simple way to set a variable in each action of an entire module (but no other module)?
This variable will be used in an output of a layout used throughout the module.
This variable would be set using a method in a modelService that launches a db-query.

If I understood correctly, I could do this in an interceptor, but isn’t there an other way?

best regards,
Mikaël

You could also set it in a “preHandler()” method in each of your handlers, or you could use a “before” advice with WireBox AOP and either annotate all the handlers in that module or match them with some regex.

I think the interceptor approach is the easiest since it is simple and has no code redundancy. The trick will be to use the evenPattern annotation on the interceptor so it ONLY fires for events in that module.

void function preProcess(event,struct interceptData) eventPattern="^myModule:" {
  event.setValue( 'myKey', 'myValue' )
}

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Bard - Nice!

I never knew about evenPattern - is that CB3 compatible?

Yes, it is. eventPattern actually came out with ColdBox 3.0. You should still upgrade though :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Thanks!
I already thought an interceptor would be best, I don’t like adding something like that to my handlers.
I didn’t know about eventPattern as well. That simplifies a couple of things here. :slight_smile:

Mikaël