Reputation: 9652
This is my URL:
http://localhost/techsupportscam/index.php/question/search/2?category=XP+Support
Now I want to convert into something like this:
http://localhost/techsupportscam/index.php/question/search/2/XP+Support
My Controller is question
and method is search
.
My link is:
<?php echo Yii::app()->createUrl('question/search/',array('id'=>$subCategory->id,'category'=>$subCategory->title)); ?>">
How I can do this? Can you guys please help me?
Thanks
Upvotes: 2
Views: 118
Reputation: 752
You can achieve this as this on CUrlManager rules,
'rules' => array(
'question/search/<id:\d+>/<category>/*' => 'question/search',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
Upvotes: 2
Reputation: 8726
You can do this from your urlManager rules in application configuration file. Add this bellow line in rules array.
filePath: protected/config/main.php
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'<controller:\w+>/<action:\w+>/<category:([^~,]+)>' => '<controller>/<action>',
...........
...........
Upvotes: 1