我现在想从ZF2升级到ZF3,在ZF3中使用URL参数有以下问题。
在ZF2中,我使用HelperPluginManager来获取Application,然后是MvcEvent,最后是routeMatch
$routeMatch = $this
->getHelperPluginManager()
->getServiceLocator()
->get('Application')
->getMvcEvent()
->getRouteMatch();
$parameterAction = $routeMatch->getParam('action');在ZF3中,使用getServiceLocator()有一个不推荐的警告(这很有意义,因为它只从ServiceManager返回creationContext )。我想找到一种不触发警告的方法。
将Application配置为使用工厂的类(使用\Zend\Mvc\Service\ApplicationFactory::class)也不起作用,因为:
Zend\View\HelperPluginManager只能创建Zend\View\Helper\HelperInterface和/或可调用的实例。
有没有任何方法可以在我的模板中获取Application上下文(或者更好的方法,甚至是URL的参数)?
发布于 2017-11-30 17:26:28
您的问题标题是"ZF3:在PhpRenderer中读出url参数“,而在您的问题中,您又问了另一个问题。
您可以在任何控制器(在ZF3中获取URL参数)中获得这一点:
$URLparam = (string)$this->params()->fromQuery('parameter', '');发布于 2017-12-07 07:58:26
对于routeMatch,如果您有一个MvcEvent,只需使用;
$event->getRouteMatch()如果你有集装箱;
$container->getApplication()->getMvcEvent()->getRouteMatch();如果您想在视图中访问routeMatch,除了视图助手(如tasmaniski/zend-当前路线 )之外,没有其他方法
https://stackoverflow.com/questions/47577683
复制相似问题