I want to know if there is a way to access at the module instance from a model. In my module configuration I have some components which I need to call in a model class, the model is defined only inside my module. I know the method Yii::$app->getModule('my-module')
but this mean that the module have to be defined every time with the same name, from controller's module I can access as $this->module->component-name
, something similar in the model?
Asked
Active
Viewed 1,036 times
1

lalithkumar
- 3,480
- 4
- 24
- 40

MarBer
- 535
- 1
- 5
- 22
2 Answers
1
Yes you can access the module instance like this:
$module = MyModuleClass::getInstance();
Then you can get id via
$module->id
For more information check here

lalithkumar
- 3,480
- 4
- 24
- 40
-
-
-
-
@MarBer Bizley provided right answer, lalith provided wrong answer and just copied right one from Bizley and edit his, that's just not nice... – Yupik Jul 24 '17 at 12:53
-
@lalithkumar - i see edit history and time of adding answer. Please don't lie. – Yupik Jul 24 '17 at 12:57
-
I choose lalithkumar answer because he edit my question before answer, the answer, if we ignore the edit, are the same. How we can resolve this? Sorry @Bizley for not choose your answer but I have consider, like I write above, the edit work done by lalithkumar, if I can do something... – MarBer Jul 24 '17 at 13:04