In design
and development
modes, I believe that the routes are re-generated on every request, which is why you're losing the value in the application
scope.
That said, the application
scope would not be a good place to persist your routes because the application
scope is refreshed when your application is reloaded. (You probably already knew that though.)
One way that you can create a fully dynamic route is like this (though I admit it is a little ugly):
<cfset addRoute(name="page", pattern="[folder1]/[folder2]/[folder3]/[folder4]/[folder5]", controller="pages", action="show")>
<cfset addRoute(name="page", pattern="[folder1]/[folder2]/[folder3]/[folder4]", controller="pages", action="show")>
<cfset addRoute(name="page", pattern="[folder1]/[folder2]/[folder3]", controller="pages", action="show")>
<cfset addRoute(name="page", pattern="[folder1]/[folder2]", controller="pages", action="show")>
<cfset addRoute(name="page", pattern="[folder1]", controller="pages", action="show")>
<cfset addRoute(name="root", pattern="", controller="someController", action="someAction")>
Then if the routing needs to be controlled dynamically via database, you can do the appropriate querying in controllers/Pages.show()
with params.folder1
through params.folder5
.
Notice that these dynamic routes should go after any other route that you need to specify, but just before the empty root
route.
You'll also want to look and see if the ColdRoute plugin that Tom mentions in his answer does anything with wildcard routes.
Something like this is most appropriate because the routes should be hard-coded in config/routes.cfm
. Do not fight this.