Answer the question
In order to leave comments, you need to log in
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
In init() of the model, you need to assign the module name
public function init()
{
$this->module = Yii::$app->getModule('mymodule');
parent::init();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question