I have ZF2 application in some cases I want to get parameter ‘number’ from the routing and make it available to all views. I tried to use events but problem with my solution is that $number is then available only in the layout and not in the views.
Here is my code
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach( __NAMESPACE__, 'dispatch', function ( $e ) {
$route = $e->getRouteMatch();
$number = $route->getParam( 'number' );
$view = $e->getViewModel();
$view->setVariable( 'searchQuery', $number );
}, 90 );
Any thoughts?
Problem solved it is accessible in view through
More about this topic is available here