writing fancy URL translation rules

good evening everyone,

i admit yii is a good framework but the lack of well written manual can keep it from spreading.

url rules designing in CUrlManger is a fancy that require a lot imagination to master.

now i need my route to work like this:

controller/abc/xyz/123 should be interpreted as controller/actionIndex/?target=/abc/xyz/123


controller/create and controller/update should be interpreted as controller/actionCreate and controller/actionUpdate

how should i design the url translation rules?

thank you so much in advance

Not sure how you would solve the first example, I’m still learning myself this myself.

But let’s assume you have an advanced pattern/rule in place, set to solve your first routing. Then to solve the other ‘problem’ it’s really easy.

The URL is parsed through the rules until it comes across the first one that matches. So, it would something like this:



	'showScriptName' => false,




		'advanced rule'=>'that I dont know how to set',



That way, when you supply an URL like serverdomain/controller/create it will match the first rule. Second with update, and the more advanced rule down there at third place wont kick in.

Now all you have to do is figure out the advanced rule. Good luck!


Ok so I’ve toyed around with this for exercising reasons, and I’ve found one pattern that works like you want. I have no idea why you’d want it set up like that though, I’ll give you that :)



	'showScriptName' => false,







May require some extra testing, but I know for a fact that when I try the third rule out with serverdomain/controller/abc/xyz/123/ and var_dump my $_GET’s, I have:

‘target’ => string ‘/abc/xyz/123’ (length=12)

To explain the rule a bit:

‘controller’ at start matches the word controller.

/* basically means “any amount of parameters afterwards”. I had to put this in since we can’t treat /abc/xyz/123 as ONE parameter.

Which is actually what we do anyway inside the gt/lt tags:


Here we say that what comes next is a GET parameter we want to name ‘target’. And the part to the right of the colon : is REGEXP. I didn’t know this from the start that this part was suppose to be regexp. Yet, it says so in the API reference, so checking there is fruitful at times! Try it!

So, once again:


The right part here is a simple regexp that matches basically:


You’re welcome.

just lick tackle says:

have you read through this article?

Thats the post I used to learn the Yii Url manager.


will actually rewrite a url looking like




is this what You were looking for?

btw note that controller in the first url is the literal string ‘controller’ not a dynamic variable

if you want to be able to assign the controller name as well you will need somthing like


NOTE: i have not tested these rules, just off the top of my head. :wink:

If you want meant that string "/xxx/yyy/123" are actyually three different variables say "/varOneName/varTwoName/varThreeName"

this becomes


NOTE: in the above please note that I use a \word regex to validate the parameter value.



//will be rewritten to


if you need to put other data into the parameter values use another regexp