In the file main.php at views/layouts/main.php
, I want to add few classes to the body tag and add css class 'active' to the navigation bar items according to the view being displayed. Is there any way I can get action id in main.php?
I hope that html is not req
Or you can use:
Yii::$app->controller->id // get controller name
to access the controller, and:
Yii::$app->controller->action->id // get action name
for getting the current action id. But put this directive at the top of file:
use Yii;
In a layout you can access the current controller via $this->context
, and so the current action id by $this->context->action->id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With