I want to get current module name in its controller action method
Any help is greatly appreciated
public function initAction()
{
parent::initAction();
die(var_dump(module name here));
}
Thanks!
I think easiest way to getting current module name is using magic __NAMESPACE__ constant.
In your controller, try this:
$modulename = explode('\\', __NAMESPACE__, -1);
var_dump($modulename); // [0] => 'Application'
You can also get a list of loaded modules via ModuleManager like this:
$manager = $this->getServiceLocator()->get('ModuleManager');
$manager->getLoadedModules();
$manager->getLoadedModules(); returns an array which contains the names of the loaded modules. You can for example check weither a module is loaded or not (if(in_array('moduleName',$manager->getLoadedModules())))You can get it from the current namespace.
Within your controller action you can do this :
public function initAction()
{
parent::initAction();
$controllerClass = get_class($this);
$moduleName = substr($controllerClass, 0, strpos($controllerClass, '\\'));
die($moduleName);
}
Example :
Administration\Controller;Administration