I just cannot figure out a way to do the former in Coldbox while
preserving the later? I suppose that I can put everything in a
rewrite map file (e.g. point www.mysite.com/dogs to "general.dogs")
but then I wonder if I am dong that, am I better dumping CB version of
SES URLs altogether and do everything via a server re-write?
So I guess I have 2 questions here: first, how *do* I create these
URLs in CB, and second - regardless of #1 - what do people believe the
best practice is here - using the server re-write, CB routing or a
hybrid?
I have a handler that simply displays landing pages. In my routes file, I grab the metadata for that handler and dynamically create routes based upon the method names (and an attribute like addPrettyRoute=“true”).
If I have this URL: www.mysite.com/dogs, CB will route to dogs.index
by default. I am looking for it to route to something like:
'animals.dogs' while still having www.mysite.com/catalog/food resolve
I'm sure it's easy, but pouring over the docs, I could not see how to
do this specific type of routing solely within CB (aside from removing
the 'index,cfm' in mod_rewrite or IIS) unless I wanted ALL of my URLs
to be top level and default to a single handler...
I know how to do this in mod_rewrite... and I could create a mapfile
with 100 of these in there if I wanted to... I was just wondering how
to do it within CB?
Or, you could add a PathInfoProvider(Event) method to your routes.cfm file and return a route that fools the ColdBox SES. Here is an example (I just typed it in this chat. Check the regex
// one route to rule them all
addRoute(pattern=‘foobarfakething/:action’,handler=’
// This method provides the SES interceptor with the CGI.PATH_INFO (if it exists).
// This method allows you to modify the CGI.PATH_INFO used by the SES interceptor before it has
// access to the value.
function PathInfoProvider(Event) {
if (reFindNoCase('^/(dogs|cats|birds|flowers)/",CGI.PATH_INFO) > 0)
{
return 'foobarfakething/#cgi.path_info#;
}
return CGI.PATH_INFO;
}
Aaron that is very useful to know, I must admit this must have not long been added. I missed or haven’t read the docs since it was added, but this is a great little addition.
But I have one question, it is not very clear in which part of the application flow it is applied. In other words it would be nice to know what other parts of the ColdBox framework is already available or what is not available to be used to help with the UDF.
If the UDF exists within the routes.cfm file it is called by the SES interceptor to obtain the CGI.PATH_INFO value. The SES Interceptor routes requests during the preProcess() interception point. The UDF is provided the Event object via arguments. Otherwise, the UDF can access anything that is available during the preProcess() event such as plugins.