Question about urlManager

I read guide to url manager. I have question is it possible to create rule for example:

‘about_us’ => ‘site/pages’ and add constant id to GET parameters for example

example.com/about_us would be equal to example.com/index.php?r=site/pages&id=4

Everything’s possible with Yii :D




'about_us' => array('site/pages', 'defaultParams' => array('id' => 4)),



o thx :) i don’t know how i missed it :)

but i have another problem with it, is it possible to do something like this

‘about_us’ => array(‘site/pages’, ‘defaultParams’ => array(‘id’ => 4)),

‘our_partners’ => array(‘site/pages’, ‘defaultParams’ => array(‘id’ => 5)),

because when i do something like that all URLs look like this

about_us?id=3,about_us?id=4 :(.

Try this property:

http://www.yiiframework.com/doc/api/CUrlManager#matchValue-detail

But in this situation I recommend you to create different actions "AboutUs", "OurPartners" etc.

Predicting your question about what to do, if you have many actions like AboutUs and OurPartners (too much rules and methods to write), I want to suggest a technique:

In UrlManager make a rule:




'<_a:(about_us|our_partners)>'=>'site/<_a>',

// or even a rule like this:

'<_a:([A-Za-z0-9_]+)>'=>'site/<_a>',



Then in SiteController define a method missingAction:




public function missingAction($actionId)

{

    switch ($actionId)

    {

        case 'about_us':  ...

        case 'our_partners':  ...

        ...

        default: // you can redirect or throw an exception there or call parent::missingAction($actionId).

    }

}



Thx for help that is good idea :). I didn’t know missingAction function.