How to get parameters from Route in ZF2 module? (class Module, function onBootstrap())

前端 未结 1 1951
暗喜
暗喜 2020-12-21 17:11

In controller I can get parameters from route using $this->params()->fromRoute(\'param1\')
How can I do that in Module OnBootstrap() function? <

相关标签:
1条回答
  • 2020-12-21 17:27

    As user2257808 said in his comment, onBootstrap is called before routing takes place, so there is not any RouteMatch to get. He suggested attaching to EVENT_RENDER, that may be too late in your case.

    I would do something like this, attaching to MvcEvent::EVENT_DISPATCH.

    MyModule\Module.php

    class Module {
        public function onBootstrap(MvcEvent $e) {
    
            $e->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH,
                function($e){
                   var_dump($e->getRouteMatch());
                    exit;
                }
             );
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题