V
V
Viktor2015-06-26 17:41:27
Yii
Viktor, 2015-06-26 17:41:27

Yii2 - how to get module ID for model or widget?

Good afternoon.
Is it possible to get the identifier of the module to which they refer from a model instance or a widget using standard Yii2 tools?
Similar to $this->module controller, only for models and widgets.
For example, for the `app\modules\comment\models\Comment` model, the module will be `comment`
Previously, I did a "crutch" analysis based on the namespace, but perhaps there is something ready

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Gogolinsky, 2015-06-26
@VitProg

In init() of the model, you need to assign the module name

public function init()
    {
        $this->module = Yii::$app->getModule('mymodule');
        parent::init();
    }

Dependency injection

A
Artem Gribkov, 2015-06-26
@L1Qu0R

Will Yii::$app->controller->module not work?

A
Alexander Makarov, 2015-06-26
@SamDark

No.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question