Yii2 routes definition in modules

后端 未结 3 829
太阳男子
太阳男子 2021-01-12 19:20

Is there any solution to add routes from module configuration?

Example. We have main config where we describe

\'components\' => [
    \'urlManage         


        
3条回答
  •  暖寄归人
    2021-01-12 20:15

    And this will be more clean and reliable. I have found this on Yii2's github repo here.

    getUrlManager()->addRules([
                [
                    'class' => 'yii\web\UrlRule', 
                    'pattern' => $this->id, 
                    'route' => $this->id . '/tools/index'
                ],
                [
                    'class' => 'yii\web\UrlRule', 
                    'pattern' => $this->id . '//', 
                    'route' => $this->id . '//'
                ],
            ], false);
        }
    }
    

    and just configure your main.php config file's bootstrap section as

    'bootstrap' => [
        'log',
        'webmasters'
    ]
    'modules' => [
        'webmasters' => [
            'class' => 'backend\modules\webmasters\Module'
         ]
    ]
    

提交回复
热议问题