F
F
flametrong2017-06-23 12:25:14
Yii
flametrong, 2017-06-23 12:25:14

How to clean up URL in config file in YII2?

Good afternoon, please teach
YII2/config/web.php

//блок с ЧПУ
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [

'news/<action>'=>'class1/<action>',
'pages/<action>'=>'class2/<action>',
'webs/<action>'=>'class3/<action>',

'<get1>/<get2>/<get3>/<get4>/<get5>'=>'site/index',
'<get1>/<get2>/<get3>/<get4>'=>'site/index',
'<get1>/<get2>/<get3>'=>'site/index',
'<get1>/<get2>'=>'site/index',
'<get1>'=>'site/index',
''=>'site/index',//главная
],
],

I have pages on my site where I want to use a dynamic number of GET parameters. How to be? Fill in each count ( 2,3,5, etc. ) in a separate rule?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-06-23
@qonand

It is better to implement a url-rule that will form / parse the url according to the parameters you need

A
Alexey, 2017-06-23
@masterfreelance

If there are not infinitely many parameters and you don’t want to create your own class from UrlRule, then you can do this:

'rules' => [

'news/<action>'=>'class1/<action>',
'pages/<action>'=>'class2/<action>',
'webs/<action>'=>'class3/<action>',
[
   'pattern' => '<get1>/<get2>/<get3>/<get4>/<get5>',
   'route' => 'site/index',
   'defaults' => ['get1' => null, 'get2' => null, 'get3' => null, 'get4' => null, 'get5' => null],
],
],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question