Question:
There is a base class for all modules
namespace app\components;
use Yii;
class Module extends \yii\base\Module
{
public function init()
{
parent::init();
var_dump(Yii::$app->controller->id); // null :(
}
}
All modules extend from it, i.e.
namespace app\modules\test;
class Module extends \app\components\Module
{
//
}
How can I get the name of the current controller in the module's base class?
Yii::$app->controller->id
returns null
Answer:
Well, not to start
Yii::$app->controller->id
a
Yii::app()->controller->id
Then it will give you the name of the controller.
//UPD
You call it from the module's init() . What can this call give you, if it does not mean which controller you have now. He will always show you NULL!
and if that's the question
How can I get the name of the current controller in the module's base class?
then the answer is no. because the module does not know anything about the controller to give out some information.