bas_vdl
(Bas Vdl)
1
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!
softark
(Softark)
2
<?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
bas_vdl
(Bas Vdl)
3
I changed the creatURl as you suggested, but i get the same result:
/post/8.html?title=proin-in-mauris
softark
(Softark)
4
IIRC, "\w" does not include "-".
So try this:
'post/<id:\d+>/<title:[\w\-]+>' => 'post/view'