[coldbox-3.6.0] My First Module Route

www.site.org/index.cfm/bobd

that’s the URL I want to be able to send others to use so I wrote this in routes.cfm (root config of application, not in the moduleconfig):

addModuleRoutes(pattern="/bobd", module=“Activity”, handler=“home”, action=“show”, id=“1”);

It’s temporary…the client just wants it to test something. Activity is the module, home.show the handler/action and normally there would be a parameter of id=1 in the URL. This is the FIRST in the list of routes in config/routes.cfm

The result is that it goes to Activity:home.index rather than home.show/id/1. I tried putting a more “standard” route in the modules config file, but then I get a bad handler exception of “bobd.index” does not exist…which of course, it doesn’t.

Grinding through the documentation, this syntax seems correct but I must be overlooking something.

Any pointers / advice?

Mike

Hi Mike,

A bit of the blind leading the blind, but I didn’t see that you could add the id part at the end in the way you did. Was that in the docs? I have just been playing with Routes.cfm file. If you want to end up at “home.show/id/1” would this work:

addModuleRoutes(pattern="/bobd/id/:id", handler=“home”, action=“show”);

David

Thanks David. This is a small event site and the client wants short URLs and is not interested in services like bitly. The goal is to try to achieve codenames for events that tie to an action and an id…so what you suggested above is absolutely correct if I was going to pass the ID in the URL. The goal is to not have to so that

www.site.com/bod

translates to

www.site.com/activity/home/show/id/1

so for now, I want to test by hard coding the id that matches the codename. Ultimately, if I cannot compact the whole thing into one small codename in the url, I would use what you suggested in the form of event/id/1…they won’t like that, but it’s shorter.

Mike

Mike,

I think you maybe over analyzing the problem again, as you are clearly stating that the id will always be one, then the only option is to then set the ID to a default of one if it is not passed into the handler. But if the handler requires ID = 1 and nothing else, why not just define it to 1 in the handler?

That’s very true…but in reality, I’ll have several events to test and don’t have the time to build this via data correctly right now so I wanted to at least write the stub of the handler to accept the the id value in RC “as if” it were passed through the URL or form submission. I think I’m giving it just the right amount of thought. Since I don’t see everyone jumping up and down about how it’s “like this” or “like that”, I’ll assume this is not going to work.

Thanks,
Mike

If there are a finite number then perhaps you could create a look-up table and do something like:

www.site.com/bodwww.site.com/activity/home/show/

www.site.com/fredwww.site.com/activity/home/show/

www.site.com/stevewww.site.com/activity/home/show/

Then do a look-up if the original bit was

bod -> www.site.com/activity/home/show/id/1

fred -> www.site.com/activity/home/show/id/2

steve -> www.site.com/activity/home/show/id/3

David