ZF2 - Get controller name into layout/views

前端 未结 9 1593
逝去的感伤
逝去的感伤 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:32

    In zf2 beta4 it made in this manner:

    public function init(ModuleManager $moduleManager)
    {
    
        $sharedEvents = $moduleManager->events()->getSharedManager();
        $sharedEvents->attach('bootstrap', 'bootstrap', array($this, 'onBootstrap'));
    }
    
    public function onBootstrap($e)
    {
        $app     = $e->getParam('application');
        // some your code here
        $app->events()->attach('route', array($this, 'onRouteFinish'), -100);
    }
    
    public function onRouteFinish($e)
    {
         $matches    = $e->getRouteMatch();
         $controller = $matches->getParam('controller');
         var_dump($controller);die();
    }
    

提交回复
热议问题