Question

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

Was it helpful?

Solution

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>',
            ),

OTHER TIPS

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>',
            ...........
            ...........
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top