Issue
I'm trying to change the way Yii is showing the url for my "product" page. Now, it shows this:
localhost/~antonio/project/?r=site/product&id=HXW1410D260D0TB013&language=en
Or with urlFormat=path
localhost/~antonio/project/en/product/id/HXW1410D260D0TB013
I need the url's to look like this:
localhost/~antonio/project/en/product/HXW1410D260D0TB013
I looked into the Yii docs, but I can't find a way to do this.
Thanks.
Solution
Add the following rule to your main.php rules array:
'product/<id:[A-Z0-9]+>'=>'site/product',
so you should have something like
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'product/<id:[A-Z0-9]+>'=>'site/product',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),
essentially the rule format is as follows:
'product/<id:[A-Z0-9]+>'=>'site/product',
Terms in <> mean you are passing a variable, so
<id:[A-Z0-9]+>
means you are passing $_GET['id'] if the regex matches (if it has only capital letters and numbers).
So the rule above means if the url matches product/something, then send it to site/product and pass the "something" as a $_GET parameter called id.
Hope that clarifies.
Answered By - Avanche
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.