Adam Cameron
addRoute(
name="myRoute",
pattern="myPattern",
controller="myController",
action="myAction"
)
If I then reload the app, I can then browse to http://localhost/myPattern/myAction, and it runs. Cool.
However if I try to do this on the fly, eg:
addRoute(
name="myRoute",
pattern="myPattern",
controller="myController",
action="myAction"
)
http method="get" url="<http://localhost/myPattern/myAction>";
Then the request is handled by the /
route.
If I dump out application.wheels.routes
immediately after the addRoute
call, I see myRoute
in the array.
Equally, if I dump it out in the /
route view, then I also see it there.
So I'm wondering what the missing piece of the puzzle is that I need to do so that it's actually... used. It's like I've set it up, but I've not loaded it or something?Peter Amiri
08/10/2022, 4:06 PMPeter Amiri
08/10/2022, 10:10 PM$loadRoutes()
after the adhoc route declaration.Adam Cameron
Adam Cameron
<cffunction name="$loadRoutes" returntype="void" access="public" output="false">
<cfscript>
var loc = {};
loc.appKey = $appKey();
// clear out the route info
ArrayClear(application[loc.appKey].routes);
StructClear(application[loc.appKey].namedRoutePositions);
// load developer routes first
$include(template="config/routes.cfm");
// add the wheels default routes at the end if requested
if (application[loc.appKey].loadDefaultRoutes)
{
addDefaultRoutes();
}
// set lookup info for the named routes
$setNamedRoutePositions();
</cfscript>
</cffunction>
To me it looks like it would take me further away from the solution. It blitzes everything in the routes
array (which is gonna be the only place my newly added route would exist), and then just reloads the stuff from config/routes.cfm
. It doesn't seem to do anything that looks like it "takes the route data from the routes
array, and then [does something] to make them be actual routes that the app then "uses".
Looking at how that routes
array is used, it tracks back to https://github.com/cfwheels/cfwheels/blob/v1.4.5/wheels/dispatch/request.cfm#L86. and from superficial inspection, simply having the route in that array should be all that's needed.
I will follow through that logic and see where things aren't going according to plan, and report back (well: maybe, depends if I too-hard-basket it).