Get Current Controller

I have been using the following code to keep a menu open for several views related to a specific module:

'active' => in_array(\Yii::$app->controller->id,['dashboard'])

The problem I ran into is that when I added a new module that has a controller with the same name, it holds open the wrong menu items.

How do I get the active controller at the specific path, rather than just any controller named ‘dashboard’? I have the following controllers, each in their own module.




I haven’t used it yet, but you can try with getUniqueId()

Not checked, but try something like this:

'active' => in_array(\Yii::$app->controller->id,['dashboard']) && !is_null(\app\inventory\Module::getInstance())

Or, if you know the name of the module:


Cool. I ended up using a combination of the controller id and the module id to get it to work.

Much appreciated!