0
votes

I want to upgrade from ZF2 to ZF3 right now and has the following problem with using URL parameter in my PhpRenderer.

In ZF2 I use the HelperPluginManager to get Application, then the MvcEvent and finally the routeMatch:

$routeMatch = $this
   ->getHelperPluginManager()
   ->getServiceLocator()
   ->get('Application')
   ->getMvcEvent()
   ->getRouteMatch();

$parameterAction = $routeMatch->getParam('action');

In ZF3 there is a deprecation warning with using the getServiceLocator() (which makes sense, because it only returns the creationContext from the ServiceManager). I want to find a way not trigger the warning.

Configure the Application as a factory-using class (using \Zend\Mvc\Service\ApplicationFactory::class) also not works, because:

Zend\View\HelperPluginManager can only create instances of Zend\View\Helper\HelperInterface and/or callables.

Is there any way to get the Application context in my template (or better even the parameters of the URL)?

2
The best way is probably to get the parameters in the controller and assign those to the view. Keep your logic out of the views/templates as much as you can.halfpastfour.am

2 Answers

0
votes

Your question title is "ZF3: Read out url parameter in PhpRenderer" while inside your question you asked another one.

You can get this in any controller (get URL parameters in ZF3):

$URLparam = (string)$this->params()->fromQuery('parameter', '');
0
votes

For routeMatch, if you have a MvcEvent just use;

$event->getRouteMatch()

If you have container;

$container->getApplication()->getMvcEvent()->getRouteMatch();

If you want to access routeMatch in view there's no way except view helper like tasmaniski/zend-current-route