UnstableFractal
UnstableFractal

Reputation: 1422

Nested routing in Yii2

I've got, for example, 2 routes:

  1. /site/test
  2. /site/test/foo

I need to write rules for UrlManager so it'll pass first rule to TestController and second to FooController.

Can i actually do that?

Upvotes: 0

Views: 545

Answers (1)

marche
marche

Reputation: 1756

You are actually nesting 3 controllers, which i do not think is a really good idea, but you can do it like the following:

'urlManager' => [
    'rules' => [
        'site/test/foo/<action\w+>' => 'foo/<action>',
        'site/test/<action\w+>' => 'test/<action>',
        'site/<action\w+>' => 'site/<action>',
        ...
    ],
],

Upvotes: 2

Related Questions