urlManager

I want to have url’s like this http://domain.com/post/1/hello-world.html. But so far i can’t manage it in the latest version of yii. Below the deails.

config:


'post/<id:\d+>/<title:\w+>' => 'post/view'

view:


<?php echo CHtml::link('Lees meer...', $this->createUrl('post', array('id'=>$data->post_id,'title'=>$data->post_name))); ?>

current result:


http://yii.dev/site/post/8.html?title=proin-in-mauris

preferred result:


http://yii.dev/post/8/proin-in-mauris.html

Thank you for your help!


<?php echo CHtml::link('Lees meer...', $this->createUrl('post/view', array('id'=>$data->post_id,'title'=>$data->post_name))); ?>

The first parameter of createUrl() should be the route, usually in the format of ‘controller/action’.

CController::CreateUrl

I changed the creatURl as you suggested, but i get the same result:


/post/8.html?title=proin-in-mauris

IIRC, "\w" does not include "-".

So try this:




'post/<id:\d+>/<title:[\w\-]+>' => 'post/view'