How to find out the name of the current module in the yii2 component?

    1 answer 1

    Try Yii::$app->controller->module->id

    • Nope Is empty. It works in controllers, but not in the component. - Max.
    • What is the component at all? As an alternative, you can pass an attribute to the component module name - Yaroslav Molchan
    • Component checks guest or not. If not a guest, then redirect to the office. In general, it has many functions, it is one of many. It clings through the bootstrap section. As a result, the problem is this: if not the guest and the current module is not cabinet, then redirect the user to the cabinet. If a guest, then do nothing. - Max.
    • @ Maxim everything should work if the namespace and use Yii are specified use Yii || \Yii - Blacknife