Sheraz Ali
Sheraz Ali

Reputation: 315

Remove parameter name from url in Yii

I am using Yii::app()->createAbsoluteUrl("sports", array('q' => 'football'))) this to print example.com/sports/football but it prints like this example.com/sports/q/football. How would we remove parameters name in this case "q" from url.

main main config file looks like this:

'urlManager' => array(

        'urlFormat' => 'path',
        'showScriptName' => false,
        'caseSensitive' => false,
        'rules' => array(
            'search/<q>' => 'search/index',
            'sports' => 'sports/index',
            'sports/<q>' => 'sports/index',
        ),
    ), 

Upvotes: 1

Views: 1113

Answers (1)

Jonnny
Jonnny

Reputation: 5039

sports/<q:\w+> => 'sports/index

or

sports/<q:[a-z-0-9-]+> => 'sports/index

depending if you need hyphens between words

CreatUrl should possibly be

Yii::app()->createAbsoluteUrl('sports/index', array('q' => 'football'))

Upvotes: 1

Related Questions