Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current module object from model in Yii2

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.

like image 904
LostDok Avatar asked Jul 03 '16 16:07

LostDok


2 Answers

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; 
like image 180
ScaisEdge Avatar answered Oct 19 '22 05:10

ScaisEdge


we can identify the module,controller and action method as follows in yii2
Yii::$app->controller->module->id;(For Getting Module ID)
Yii::$app->controller->id;(For Getting Controller ID)
Yii::$app->controller->action->id;(For Getting Controller action ID)

like image 43
raghavendra Avatar answered Oct 19 '22 05:10

raghavendra