简体   繁体   中英

yii routing with parrameters

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 mysite.com/site/page/view/faq and I want it to generate simply mysite.com/faq.

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

Your rule should be something like:

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

This means that if you generate a url to site/page that has a view parameter, then it'll just go to view. The rule will get skipped if you don't have a view parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM