controller and action mapping question

Sorry if this has already been asked…

is there a way that i can map this url

/my-custom-directory/my-action/

directly to MyCustomDirectoryController and to actionMyAction?


This is how zend framework works and wondering if i can mimic this.

Can I do this with a setting in Yii?

I don’t want to hack anything or add in any routes.

any help would be much appreciated.

Take a look here: http://www.yiiframework.com/doc/guide/topics.url

Read “Parameterizing Routes” section. I haven’t used it yet, I am developing systems for private usage and I don’t need to care about seo.

I wonder it help you.

Anything else, ask us! :)

not really the answer i was looking for.

i have an existing site written in zend that i wish to migrate over to yii without needing to write 30 routes.

the controllers and actions all follow the url example ‘/product-directory/blah-action/’ that should map directly to ProductDirectoryController and actionBlahAction.

Is there an easy way to do this without adding routes.

Is this a feature of yii? If not i reckon it should be.

One rule should be sufficient. Not tested though:


'my-custom-directory/<_a:[^\/]+' => 'myCustomDirectory/<_a>'

Regexpattern wasn’t closed in Mike’s example:




'my-custom-directory/<_a:[^\/]+>' => 'myCustomDirectory/<_a>'



thanks but still not what im looking for. In my first post i asked

“Can I do this with a setting in Yii? I don’t want to hack anything or add in any routes.”

I have 30 odd controllers (that follow the camelcase naming scheme). All with different actions. Its just not efficient going with so many routes.

You’ll need a rule in any case and this is no hacking but configuration ;). With the right regular expressions 1 single rule is sufficient. Did you read the section on parameterized url rules? It gives an example with a rule that contains all possible controller/action names. You can even replace that with a “match all” expression if you don’t want to specify all controller/action names.

Sorry, i think now i understand. You want a mapping like this:


my-controller-a -> myControllerAController.php

my-controller-b -> myControllerBController.php



As this is a very specific requirement i don’t think, this will be added as feature. But you always have the option to extend CUrlManager and override it’s createUrl and parseUrl methods and add your preferred logic there.

yes thats exactly it Mike.

I’m looking into overriding these methods now.