简体   繁体   中英

YII urlManager rewrite singe URL with multiple parameters

Ok, removed my previous question and reformulated the new one, otherwise no one would understand, sorry. So here the problem that's left:

So I want to rewrite an URL to a single word which works with zero, one and two parameters, but not with 3:

Original url with 2 paramaters:

index.php?r=site/page&view=exposities&tijd=nu

urlmanager rule:

'exposities_nu'=>array('site/page', 'defaultParams' => array('view' => 'exposities', 'tijd'=>'nu')),

result:

/exposities_nu/

Now what doesn't work:

Original url with 3 parameters:

index.php?r=site/page&view=exposities&tijd=vestiging&locatie=1

urlmanager rule:

'knsm'=>array('site/page', 'defaultParams' => array('view' => 'exposities', 'tijd'=>'nu', 'locatie'=>'1')),

result:

index.php?r=site/page&view=exposities&tijd=vestiging&locatie=1

Does anyone why this last url isn't shortened to /knsm/?

Maybe you didn't set the url in the URL Manager right. See this example:

return array(
    ......
    'components'=>array(
        ......
        'urlManager'=>array(
            'urlFormat'=>'path',
            'rules'=>array(
                'post/<id:\d+>/<title:.*?>'=>'post/view',
                'posts/<tag:.*?>'=>'post/index',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),
        ),
    ),
);

Also you have to create you URLs correct:

Yii::app()->createUrl('post/view', array(
            'id'=>$this->id,
            'title'=>$this->title,
        ));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM