Jap Mul
Jap Mul

Reputation: 18769

yii url rewrite

I'm using Yii and I want to change the URL path. At this point I have a URL like this:

controller/action/param1/value1/param2/value2

and I want it to be like:

controller/value1/value2

or maybe would be fine too:

controller/action/value1/value2

How can I accomplish this? I tried many options in the URLManager settings but it either stays exactly the same or I get an error saying Undefined index: param2.

Upvotes: 0

Views: 589

Answers (1)

jborch
jborch

Reputation: 1136

Check the documentation for CUrlManager

Add the following line to the CUrlManager rules array in main.php

'/controller_name/<param1:\w+>/<param2:\w+>' => '/controller_name/action_name',

eg.

'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName'=> false,
        'rules'=>array(
            '/controller_name/<param1:\w+>/<param2:\w+>' => '/controller_name/action_name',
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
    ),

Upvotes: 2

Related Questions