How to get current module object from model in Yii2

LostDok picture LostDok · Jul 3, 2016 · Viewed 12.6k times · Source

I have module ticket.

Module class has propery UserClassName (string).

In this module I have model called Dialog.

Within this model, I want to get access to the module property UserClassName.

How I can get module object from my model Dialog?

P.S. From controllers I can do next: $this->module.

Answer

scaisEdge picture scaisEdge · Jul 3, 2016

You can use className() to obtain the class name.

$yourModule = yourPath\YourModule::className();   

Or for getting the module id you can use:

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