Routing Translation With Parameters

Hi all,

I spent pretty much time on it already and I’m starting to give up so… help me understand it please :)

I’m trying to make my URLs very short and it works fine with URLs without parameter but those with parameter does not work.

In my routing setting I have:




'rules'=>array(	

	'kontakt' => 'site/contact',

	'faq' => 'site/page/view/faq',

...

Then when I use in zii.widgets.CMenu (or in Chtml::link()) links as array for the first rule then it’s ok but for second not. So to be more precise

This works


array('label'=>'Kontakt', 'url'=>array('/site/contact')),

it generates http://mysite.com/kontakt URL which is what I expected.

But this doesn’t work


array('label'=>'FAQ', 'url'=>array('/site/page', 'view'=>'faq')),

i generates http://mysite.com/site/page/view/faq and I want it to generate simply http://mysite.com/faq.

I’ve read a lot and tried a lot of variations but it fails all the time… any suggestions please?

The rule for ‘faq’ is invalid, because the left hand side is not a route. It should rather look something like this




'faq' => array('site/page', 'defaultParams'=>array('view'=>'faq')),



Note though, that this will only parse incoming requests. It will not create ‘/faq’. A better solution might be, that you route all unknown URLs to that static page action. You can achieve this with a final URL rule like this:




`<view>' => 'site/page',



This will parse and create not only ‘/faq’ but all static pages for you. You need to use the same file names for the static files as they should appear in the URL.