Yii Framework Forum: how to replace - with _ in URL - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to replace - with _ in URL what is the most effective way to globally do this? Rate Topic: -----

#1 User is offline   zydecode 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 16-December 09

Posted 16 December 2009 - 11:12 AM

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
0

#2 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 16 December 2009 - 11:26 AM

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 :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users