2

I have a view in my ColdBox application that is calling a module handler within the view like this:

#runEvent( event="mymodule:home.index" )#

Now I want to pass arguments to the module, so I changed the call to this:

#runEvent( event="mymodule:home.index", eventArguments=moduleArgs )#

Though unfortunately I don't seem to have access to the passed arguments within the module's event handler. I've dumped rc and prc, but they only contain variables I've set in the main event handler and the event argument doesn't seem to provide a method to return the passed arguments. The documentation about module event executions unfortunately doesn't provide any information about this.

Also, I realized calling event.getCurrentModule() within the module returns an empty string. I would have expected the module's name.

So, how can I access the arguments passed to a module? Is runEvent() the right function for this? Did I miss a module config setting?

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132

2 Answers2

2

You can define arguments in your function like this

function index(event, rc, prc, isRender=false) {
  writedump(arguments);
  abort;
} 

See the ColdBox runEvent() documentation.

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132
Sana
  • 61
  • 1
1

The ColdBox documentation explains how to pass additional arguments to your function. So e.g. calling

#runEvent( event="mymodule:home.index", eventArguments={foo="bar"} )#

the foo variable can be accessed via the arguments scope:

function index(event, rc, prc) {
  writedump(arguments.foo); // Dumps "bar"
}
Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132