YII urlManager rewrites a single URL with multiple parameters

Well, deleted my previous question and reformulated a new one, otherwise no one would have understood, sorry. So, here is the problem that remains:

So, I want to rewrite the URL to one word that works with zero, one and two parameters, but not with 3:

Original URL with two parameters:

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 does not work:

Original URL with three 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

Anyone why this last url is not shortened to / knsm /?

+3
source share
1 answer

You may not have specified a URL in the URL Manager. 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>',
            ),
        ),
    ),
);

You must also correctly create the urls:

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

All Articles