How ColdBox framework identifies the event handler cfc when a url fires

Hi All,

I am very new in ColdBox framework but have a good experience in ColdFusion.

In browser I am firing a url like below.

http://abc.xyz.dev.local/index.cfm?event=event.userLists&user_id=1463613.

Here the event handler named “event” is pointing to the path - \handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc. My question here is how ColdBox framework identifies this cfc file(\handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc). I know there is some config file where we can provide this handlerspath . But in my application (where I am working) I can see this file but it has been configured as just “handlers” instead of what I am expecting like “\handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc”. Please correct me if I am wrong as I dont have much knowledge about this framework.

Is there any other configuration file or any more set up can be done to map this handler to.

Your timely help is well appreciated.

Thanks in advance

Hello and welcome to ColdBox!

Ok, so the handlers folder is your default handler convention location. When you create subdirectories, those are referred to as packages.

\handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc

So you have a package of pdt.real.ldr.ldr_nm.ldr_portal.ldr_agt and a handler of event.

So by default, the URL will need to be:

yoursite.com/index.cfm?event=pdt.real.ldr.ldr_nm.ldr_portal.ldr_agt.event.userLists

Now I’m assuming you want to make that shorter? Firstly, I would ask if you really need all those subdirectories. If you do, there’s not much help in the way of the “old” query-style URL. However, consider what your URLs can look like when you enable the SES interceptor:

yoursite.com/index.cfm/pdt/real/ldr/ldr_nm/ldr_portal/ldr_agt/event/userLists

Yes, still long, but here comes the good part. Edit your /config/routes.cfm and add a line like so BEFORE the default route:

addRoute( pattern="/myrouteName", handler=“pdt.real.ldr.ldr_nm.ldr_portal.ldr_agt.event”, action=“userLists” );

Now your URL can look like this:

yoursite.com/index.cfm/myRouteName/user_id/1463613.

Or here’s one even better:

addRoute( pattern="/myrouteName/:user_id-numeric", handler=“pdt.real.ldr.ldr_nm.ldr_portal.ldr_agt.event”, action=“userLists” );

And now your URL can be even simpler (user_id will be set in the request collection for you automatically):

yoursite.com/index.cfm/myRouteName/1463613

Does that help answer your questions?

http://wiki.coldbox.org/wiki/URLMappings.cfm

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Hello Brad,

Thanks for your detailed explanation regarding the URL mapping.

Yes I really need all those subdirectories. And as you said , if there is not much help in the way of the old query style URL then why I am getting a URL like below even though this URL points to the cfc - \handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc

http://abc.xyz.dev.local/index.cfm?event=event.userLists&user_id=1463613.

That means still some configuration is there to map the cfc path (\handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc) to just “event” in the URL. Right??. Thats what I think because while hitting this url in browser it is pointing this cfc (\handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc).

Note that I can see one line of code as below in config/router.cfm. Is this the reason for the above behavior?. Just a guess but not sure.

Please correct me if I am wrong here an I appreciate your timely help on this.

Regards,

Forgot to add below line of code that I found in my config/routes.cfm.

addRoute(pattern=":handler/:action?");

Adbul, I’m unable to replicate that behavior on a test site:

http://127.0.0.1:18808/index.cfm?event=event/userLists

That URL produces a “EventHandlerNotRegisteredException”

Are you sure you don’t have a copy of event.cfc in the root of your /handlers folder as well?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Brad, I have another event.cfc (its not a copy , it contains different methods) in the root of /handlers folder. I put a cfdump inside both cfc’s - one is in /handlers/event.cfc and other dump is in \handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc. But it was dumping the content written inside the cfc - \handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc. That clearly indicates the url fired (http://abc.xyz.dev.local/index.cfm?event=event.userLists&user_id=1463613) in browser pointing to the cfc- \handlers\pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event.cfc. Right??.

This is very huge application where I am working but I could not trace it where they have configure this thing. Any other suggestions from your side?.

Sorry, but I still can’t replicate that behavior. In my test app I have two “event.cfc” handlers too. One in the root, and on in all the folders, and hitting each respective URL loads the appropriate handler.

I think there might be some more “magic” going on in your specific app and without knowing what has been configured I’m not sure what to tell you. This certainly doesn’t appear to be any default behavior of ColdBox though.

The following CommandBox commands will create a fresh site, add both handlers, start the embedded server, and open each handler. You will see that each handler outputs its respective view which is correct.

coldbox create app myApp --installColdBox
coldbox create handler event userlists
coldbox create handler pdt\real\ldr\ldr_nm\ldr_portal\ldr_agt\event userlists
start --!openBrowser --force
server open URI="/index.cfm?event=event.userlists"
server open URI="/index.cfm?event=pdt.real.ldr.ldr_nm.ldr_portal.ldr_agt.event.userLists"

If you don’t have CommandBox, download it here: http://www.ortussolutions.com/#download

The commands above can also be placed in a recipe file and executed all at once like so:

recipe makeSite.boxr

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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