How can one set the defaultRoute in yii2 to point to a module controller instead of the site controller.

How can one set the defaultRoute in yii2 to point to a module controller instead of the site controller.


$config = [

   'defaultRoute' => 'app\modules\test\controllers\DefaultController',

'modules' => [

    'test' => [

        'class' => 'app\modules\test\Module',

    ],

],

Thank you in advance- also I had seen this question being asked and answered- however most of the answers didn’t provide examples and instead directed the user to the documentation. In my personal opinion I think it would be great

if we can provide more detail answers and explanation as it will help newbies understand yii2 better. much luv to the Yii community.

Hi,

You can set following:

In main config file:

return [

…,

‘controllerNamespace’ => ‘frontend\controllers’,

‘on beforeRequest’ => [‘app\modules\test\controllers\DefaultController’,‘yourAction’],

‘components’ =>[]

]

Good luck.