Yii2 Get module name, controller name, method name
in the view:
Module name $this->context->module->id
Controller name $this->context-> ;id
Method name $this->context->action->id
in the controller
Module name Yii::$app->controller->module->id;
Controller name Yii::$app->controller->id
Method name Yii::$app->controller->action->id;
or
Module name$ this->module->id;
Controller name $this->id;
Method name $this->action->id;
In the beforeAction method of the controller ( method receives $action parameter)
Module name $action->controller->module->id;
Controller name $action->controller->id;
Method name $action-> id;
The above introduces how Yii2 obtains the module name, controller name, and method name, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.