[SOLVED] URL Manager: static pages titles

Hello,

Using the Yii URLManager component, I’d like to have static pages having a different name than the filename.

Example of redirection rule:




'urlManager'=>array(

     'urlFormat'=>'path',

     'showScriptName'=>false,

     'urlSuffix'=>'',

     'rules'=>array(

          'info/xxxxxxxx' =>  'site/page/view/howItWorks',

      ),

),


(xxxxxxxx being a different string than the text of the view file name: howItWorks.php)

With this config, the page ‘info/xxxxxxxx’ gets correctly called.

But the url attached to the HREF attribute of the HTML anchor tag generated by the createURL is still ‘site/page/view/howItWorks’ when I use a link in the CMenu like that :




items => array(

    'label'=>'SOME TEXT...',

    'url'=>array('site/page', 'view' => 'howItWorks'),

    'linkOptions' =>array('title'=>'SOME TEXT...'),             

),



What am I doing wrong ?

thanks in advance

CUrlRule::defaultParams is what you are looking for. You have to provide them in such rule and target action will see them as they were provided by user in url.

This is the only way you can define param values in url route. Right part of standard association can only specify "model/controller/action" mapping. More about costomizing url rules: URL Management

Thank you,

that was exactly what I needed.

So in the end this is the code I am using (if it can help other people) :





// Special Static pages rules

'info/xxxxx1' =>  array('site/page', 'defaultParams' => array( 'view' =>'howItWorks') ),                    

'info/xxxxx2' =>  array('site/page', 'defaultParams' => array( 'view' =>'advertising') ),


// Static pages rules

'info/<view:\w+>' => 'site/page',




Problem solved !