get controller id in Yii2 bootstrap component

I want to get controller id and its action in my component which is a bootstrap component , but Yii::$app->controller is null when component is run , I think this is due to running before controller runs .

How can get controller id in my bootstrap component ?

or is there another way to run a task after any controllers ?

thanks before .

As you already figured out, you can’t.

An event handler can be attached to before action or after action event of the application in your bootstrapping class. ActionEvent holds a reference to the requested action and the controller can be accessed as


$event->action->controller