how to replace - with _ in URL

I need to use the “-” character in my URLs, and have them map to controllers and controller functions - but of course I can’t use a “-” in my controller function names.

My main idea is to replace the "-" with a "_" when the URL is mapped to the controller/function. I know how to do this with the urlManager in the config file for distinct URLs, but I have 2 questions:

  1. as only 2 controllers need this ability, is it possible for me to add code to the init function of a controller to parse the URL and replace the “-” with “_” so that the function can be reached? It seems expensive to parse every URL when I know most don’t need this conversion.

  2. what is the most effective way to do this globally, if I need to - ie: where should I put the code and what should I use to do it: a built-in Yii parser to do the replacement, or a simple str_replace call?

Cheers,

Sean

In answer to 1), you can override CController::missingAction() and do string conversion + redirection from there. Though obviously that’s not a suitable solution if you want to deploy something like this system-wide. I’m therefore also interested in an answer to question #2 :)