ZF2 - Get controller name into layout/views

前端 未结 9 1584
逝去的感伤
逝去的感伤 2020-11-30 07:03

I know with ZF1 you would retrieve the module/controller name using custom View Helpers that would get the singleton frontController object and get the name there.

U

9条回答
  •  长情又很酷
    2020-11-30 07:35

    $this->getHelperPluginManager()->getServiceLocator()->get('application')
         ->getMvcEvent()->getRouteMatch()->getParam('action', 'index');
    
    $controller = $this->getHelperPluginManager()->getServiceLocator()
                       ->get('application')->getMvcEvent()->getRouteMatch()
                       ->getParam('controller', 'index');
    
    
    $controller = explode('\\', $controller);
    
    print_r(array_pop($controller));
    

提交回复
热议问题