D
D
Dmitry Sidorenko2015-09-29 17:35:14
Yii
Dmitry Sidorenko, 2015-09-29 17:35:14

How to set a universal CNC in Yii2?

There are URLs:

  • /catalog_banya_i_sauna
  • /catalog_banya_i_sauna/4
  • /catalog_banya_i_sauna/veniki
  • /catalog_banya_i_sauna/4/4
  • /katalog_banya_i_sauna/veniki/Venik_horoshiy_ochen

For them, he created as many as 3 CNC rules
'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => true,
            'rules' => [
                [
                    'pattern' => '',
                    'route' => 'site/index',
                    'suffix' => '',
                ],
                [
                    'pattern' => 'katalog_<modul>',
                    'route' => 'categories/index',
                    'suffix' => '',
                ],
                [
                    'pattern' => 'katalog_<modul>/<firstId>',
                    'route' => 'categories/index',
                    'suffix' => '',
                ],
                [
                    'pattern' => 'katalog_<modul>/<firstId>/<secondId>',
                    'route' => 'categories/index',
                    'suffix' => '',
                ],

And how to manage in this case one rule?
It should sound like this: Anything that starts with "katalog_" is redirected to categories/index
Thanks!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Sidorenko, 2015-09-29
@sidorenkoda

I solved the problem myself =)
Maybe it will be useful for someone:

'pattern' => 'katalog_<modul:(\w+)(/(\w+))?(/(\w+))?>',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question