Getting the Module Route

I'm thinking this is something easy I am overlooking.

In my module I am using event.buildLink() to create inter-module
links. From the forgebox module example I see the example as
event.buildlink('forgebox.install')

I want to make the "forgebox" part of the buildURL argument dynamic
because as far as I can tell the route module part ("forgebox") is
based on the route registered in the host application using
addModuleRoutes() not the name of the module.

So If I were to modify the host's Routes.cfm file and change the
pattern to use another module match all my buildLink() functions will
be broken since "forgebox" is hardcoded in buildLink().

I looked for the route pattern setting in: getSettingStructure() and
getModuleSettings( event.getCurrentModule() ) but didn't see it.

What am I missing?

thanks!

.brett

That is something that I am looking at, right this moment too.

Because it doesn't have anything, I was looking at the onLoad() to set a
setting for the module that could be used module wide.

But I am also looking at using the onLoad() to set the moduleRoute as well.
My main concern at the moment is that the onLoad() can be run twice for some
reason and I still don't know why it is.

But if there is another way to do this I am looking too, the last thing I
want to do is modify more than one location where the module route may be
used.

Ok, few things on this subject.

The entry point used in SES can be pretty much anything as you can alias it, etc. So what I am seeing is the best way to reduce that entry point in the modules so it can be transportable and easy changeable.

What i would suggest is creating a setting in the module, maybe something like this:

settings = {
entryPoint = “forgebox”
};

Then in the Routes.cfm you can use that setting register the module routes:

addModuleRoutes(pattern=getModuleSettings(“forgebox”).entryPoint, module=“forgebox”);

You can then use that setting in your build links to prefix your links. Does this make sense now.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Hey Luis,

That does makes sense but I don't think it is ideal for what I am
looking for.

The issue with using a Module setting to define the entry point is
that the entry point is still being bound to the module, so if I
wanted to modify the entry point I would have to modify the module.
Ideally the module would be indifferent to its entry point. The host
application should assign the entry point to the module and the module
would be aware of its entry point but would not explicit set it.

A use case would be if we wanted two separate forgebox modules to run
at two different entry points. The host application should assign
each module to a separate entry points, and the Modules would know
what entry point was assigned to them so they could handle inter
module linking.

An example (2 forgebox modules running on separate entry points):

  addModuleRoutes(pattern="/forgebox1",module="forgebox");

  addModuleRoutes(pattern="/forgebox2",module="forgebox");

Inside the forgebox module, I can't find how to determine what the
Module Route pattern matched to create links. I had expected it to be
in the settings struct getModuleSettings( event.getCurrentModule() )
but it's not. Is that value elsewhere in the API? So I can't figure
out from within forgebox if it is running on the forgebox1 or
forgebox2 route entry point.

thoughts?

.brett

Ahhh I think I am seeing it now. Have you used: event.getCurrentRoute() which gives you the matched route?

If not, maybe any ideas on how to enhance this?

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

event.getCurrentRoute() appears to be returning the route pattern from
the module routes, not from the host application's route.

So if I have this in my host app Route's config:

  addModuleRoutes(pattern="/myappSlug",module="myApp");

And in my ModuleConfig have

    routes = [
      {pattern=":handler/:action"}
    ];

Calling event.getCurrentRoute() returns

:handler/:action/

What I want is to find the value "/myappSlug" from within my module.

Maybe we can add a new key to the event object that is populated by
the URL slug that the host app's pattern matches when it resolves the
module. Or even a way to get a structure of the host's app's route
that matched with the name of the route that matched, the pattern, and
the value that the pattern matched.

I also noticed the method event.getRoutedStruct() returns an empty
structure from my module. Is this intended?

thoughts?

.brett

Sorry the one you are looking for is event.getCurrentRoutedURL()

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

That doesn't return what I need. That only returns the route matched
in the Module routing, not the entry part that was matched by the
addModuleRoutes pattern.

Ok, got it.

You can talk to the SES interceptor directly and ask for the module
routing table or a specific module's routes:

getInterceptor("SES").getModulesRoutingTable();
getInterceptor("SES").getModuleRoutes( module );

This should help you.