I have set the variable in module.php which i can get in the layout. now i want this variable in my controller also.
public function onBootstrap(MvcEvent $e) {
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
// $this->initAcl($e);
$e->attach(MvcEvent::EVENT_RENDER, array($this, 'setVariableToLayout'), 100);
}
public function setVariableToLayout(MvcEvent $event) {
$viewModel = $event->getViewModel();
$viewModel->setVariables(array(
'controller' => $event->getRouteMatch()->getParam('controller'),
));
}
How can i get that variable in all my controller. if i try to get the variable in controller like print_r($controller) or print_r($this->controller) it gives undefined error.
This is module.php file and i have set controller as which controller is requested., function called from onBootstrap