user5835902
user5835902

Reputation:

Yii SEO Frienbdly URL

I'm newbie on Yii, I'm facing some difficulties on create Yii SEO Friendly url.

My code is below:

echo CHtml::link($Menu->label, array('articles/view',
 'id'=>$Menu->link,  

This is my view code, currently this url:

articles/view&id=75

I need this type:

articles/75-article_name 

How can I reach this solution?

Upvotes: 0

Views: 37

Answers (1)

SiZE
SiZE

Reputation: 2267

Just add url rule to your config

return array(
    // ......
    'components'=>array(
        // ......
        'urlManager'=>array(
            'urlFormat'=>'path',
            'rules'=>array(
                'articles/<id:\d+>-<t:.+>'=>'articles/view',
                // .......
            ),
        ),
    ),
);

And don't forget to add action param public function actionView($id){}

Upvotes: 1

Related Questions