specify handler in addModuleRoutes

I have 2 modules: module1 and module2.
Both have their repsective routing set up as follows:

addRoute(pattern="/", handler=“module**[1 or 2]**”,action=“index”);


I want to go from module1 to module2, making the layout similar to the ones in module1. For that I’d make another handler, that employs logic similar to the main handler for module2, but in context on module1 (think of a “change settings page” for developers (quick and dirty with more functionalities, and a similar page for end users). So I have a main.cfc handler and a module1.cfc handler in module2. I can easily go to module1.cfc by redirecting to index.cfm/module2/module1.

But I don’t want this. Think of it being index.cfm/settings (being the entrypoint for the settings module) and index.cfm/admin (being the entrypoint for the admin module). It would be like redirecting to index.cfm/settings/admin.
I want the URL to be index.cfm/admin/settings. I can add a route like this:


But this would result in the same handler, layout, views etc as the normal index.cfm/module2.
What I’m basically asking is: is there a handler argument available for the addModuleRoutes, or is there any other way of making a route that would employ the correct handler?

best regards,


Sorry, but can you rephrase your question, I didn’t get it, sorry :slight_smile:

What I mean is, there is a handler argument available in the addRoute() method, where you can specify what handler to use, within that specific application or module. When you traverse from one module to another, you need to use the addModuleRoutes() method. But then you need to rely on the internal routing of the module you are going to, you canot specify that you want to go to a specific handler of another module, you can only go to another module in general.

Is there any way to tell the application to rewrite its content to a specific handler of a specific module:

in the routes.cfm file of a module named “transaction”:

best regards,

I am not sure I follow what you are trying to achieve either.

Could you provide some code example as to what you would like to do, this might help us understand it better. Doesn’t have to be real world, pseudo code would surfice.

But if I was to guess, you are talking about running code in Module 1, and then run code or go to an event in Module 2. Is that right?

I have been trying to come up with an alternate way of explaining my question, but I can’t seem to manage to do so…

in the routes.cfm file of a coldbox application you can use the method addRoute() to add a certain rerouting to another part of the application.
addRoute(pattern="/login", handler=“main”, action=“login”); would result in somedomain.com to go to the login event in the main.cfc handler.

I can also go to specific module using the addModuleRoutes() method.
addModuleRoutes(pattern="/customer",module=“customer”); would result in http://somedomain/index.cfm/customer to go to the customer module.

What I want to do is addModuleRoutes(pattern="/customer",module=“customer”,handler=“main”,action=“login”);.
Can somebody tell me if this is valid code or are the handler and action methods unavailable for this method. In the documentation I couldn’t make out if this method has the same arguments available as the normal addRoute() method.

Best regards,

Well you have lost me…

I will try one last time, can you tell us what you are trying to achieve. Take the routes out of the equation for now, because if it is what I think you are trying to do, then you might want to rethink your approach.

If I understand you this time, you are saying that you have TWO modules.

Module A - A fully fledged ColdBox module, with module config roues define as per your OP.
Module B - Same as Module A in setup.

You are asking how do you provide a settings action that could be available to both the Modules, which you indicated by saying.

It would be like redirecting to index.cfm/settings/admin. I want the URL to be index.cfm/admin/settings

But above you are now saying something completely different, so it is making it hard to decipher what you are trying to achieve. I assume because you have your own modules, with which you state they have their own routes. Why you can’t apply the routes and handling there to begin with. Then use a global service called settingService@whatever, that could be injected into wherever you need it and execute the global service to do what you need it to do.

By me asking you what are you expecting, was like saying I wanted to hear.

When the user goes to either /admin/settings or /user/settings how could I share the code between the two modules. Or whatever you expect the flow to be.

Which is why I wanted to know why you had decided to add the routes to the global config, rather than the module config or whether you didn’t know about adding routes at the module level and encapsulate the routes into the module, in case you want to move the module around and not have to keep adding routes to the main application.

Alright, I’ll try and leave out the routes. From my standpoint it doesn’t look like a complicated question, though, I’m actually just asking if the addModuleRoutes method has the “pattern” argument available…
I’ll try and rephrase my question, with the example of what I am trying to do.

I have an application running, a shopping application. This shopping application has a basket/shopping cart module called basket. When clicking the appropriate button in the application, you’d be redirected to index.cfm/basket. This is a fully functional application on its own (which is why I wanted to use modules, since they can easily be transfered to or shared with other applications).
You also have a customer button, in a manner of speaking. This would redirect you to an index.cfm/customer page, where you could create a new user for yourself or manage an account.

In the basket module, there is also a customer button. This would redirect the user to index.cfm/basket/customer and would land the user in the appropriate page in the customer module. I want to be transfered fully over to the customer module, but want to use a number of functionalities, layouts and views from the basket module. this would mean that, for example the customer creation page would have a design and HTML structure more closely fitting to the basket pages, even incorporating the same header and footer (with some differences in content), using the javascript files for those functionalities, etc… BUT, it would ultimately still be a part of the customer module.
This means that I mostly want to use the logic from the customer module, and all HTML that accompanies it (HTML form, javascript, …) and merge it with some layouts, views and javascript files that are specified in the basket module. To me this means I would emloy a handler/model/service/… residing in the customer module, that would fetch layouts and views from the basket module.

That last bit is just fine, I’m having no trouble in doing that. But right now, the main customer handler is used (customer.main.cfc). I wanted to use another handler file for the basket-customer pages, since they will also hold different features and functionalities. I don’t know how to get there. I don’t know how to rewrite the content behind my URL (which is why I brought up the routes file) all the while avoiding using the customer.main.cfc handler.
I know how to do this in IIS, which is part of my setup, but I wanted to keep my rewriting grouped as much as possible.

Anyway, I wanted to thank you already for trying to comprehend my question here. I really appreciate it!

Best regards,

Ok now that makes sense to me, the problem is that you are not going to achieve it this way. However what you can do, as these modules by the sounds of it, are never going to be independent of one another. If they have that requirement, then the following will not work.

If you structure your modules right, you could do something like this.

Lets say where are in basket and click the customer button. We could then have the customer button run the action /basket/customer or you could run /whatevermodule/customer and either have a handler in each module do this

Basket Handler

btw this is wrong

Basket Handler

I’m pretty sure you understood now what I was trying to accomplish. Thanks for the extensive amount of possibilities offered.
I hadn’t heard of viewlets before. When searching the docs, I found some words on them on the bottom of the layouts & views page, and they actually make a lot of sense here. Using these, I think I could create the best solution to keep my content separated. Not entirely separate, but enough to be independable. As far as I can follow the docs here, I could essentially place customer button in the basket page, make that button load an event in my basket module (instead of my customer module as I had intended to do) the returns a layout form my basket. And in that layout I could call upon a viewlet event from the customer module. And I could create separation by only rendering that customer button if the customer module is loaded. It isn’t complete isolation, but it opens the possibilities for interaction between my modules without them breaking if one of them isn’t used in some form of application.

Thank you for all your suggestions!

Best regards,

Yep… And the strange thing is that this is what I thought you might have been trying to explain, but needed to clarify what you wanted to achieve…