neilc
(Caphonic)
1
Hi there
I have the following in my main config array
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'category/<action:\w+>' => '/category/GetTopLevelCategory',
'product/<action:\w+>' => '/product/GetOneProduct',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
),
'showScriptName'=>false,
)
This works fine and the url
DOMAIN.com/product/awesomeproductname
goes to the getOneProduct action of the product controller.
However I would like the url to be
DOMAIN.com/product/awesome-product-name
But this doesnt work and I get a 404 error. How do I make the route take dashes ?
Thanks
drylko
(Pawel Drylo)
2
Hi,
pearl regular expressions does not include dashes in ‘\w’.
Try with that:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
(...)
'product/<action>' => '/product/GetOneProduct', //or
'product/<action:.*>' => '/product/GetOneProduct', //but former is shorter <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/wink.gif' class='bbc_emoticon' alt=';)' />
(...)
),
'showScriptName'=>false,
)