I have a handler located at /handlers/user.cfc
This CFC contains a few user-related methods, including register(), which corresponds to the URL /user/register. It all works fine. We’re using SES URLs.
Users have a variety of other objects they can create and work on. Reports, jobs, etc. I want functionality related to a user’s reports located in /user/reports/[more pages here], and for jobs in /user/jobs/[more pages here], etc.
To do so, I created a user folder to hold additional handlers, so my /handlers directory now looks like this:
/handlers/user.cfc
/handlers/user/reports.cfc
/handlers/user/jobs.cfc
The problem is that after adding the folder /handlers/user, when I request the URL /user/register, instead of locating the user.cfc handler in the root of /handlers, and calling the register() method on that handler, ColdBox instead sees the /handlers/user subdirectory, and looks for a register.cfc handler with an index() method in it. That register.cfc handler doesn’t exist, and I get the error “The event: user.register.index is not valid registered event.”
I can fix the problem by adding this route to my config/Routes.cfm:
addRoute(pattern=“user/register”, handler=“user”, action=“register”);
My questions are:
- Is it a bad idea to have both /handlers/user.cfc and a subdirectory in the handlers folder with the same name?
- If it is a bad idea, what do you recommend instead?
- If it’s not a bad idea, is the preferred solution adding an explicit route like I’ve done, or is there a better way?
Thanks,
Conan