[英]ZF3: Read out url parameter in PhpRenderer
I want to upgrade from ZF2 to ZF3 right now and has the following problem with using URL parameter in my PhpRenderer. 我想立即从ZF2升级到ZF3,在我的PhpRenderer中使用URL参数有以下问题。
In ZF2 I use the HelperPluginManager
to get Application
, then the MvcEvent
and finally the routeMatch
: 在ZF2中,我使用
HelperPluginManager
来获取Application
,然后是MvcEvent
,最后是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
). 在ZF3中,使用
getServiceLocator()
会发出弃用警告(这很有意义,因为它仅从ServiceManager
返回creationContext)。 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: 将
Application
配置为工厂使用的类(使用\\Zend\\Mvc\\Service\\ApplicationFactory::class
)也无法正常工作,因为:
Zend\\View\\HelperPluginManager can only create instances of Zend\\View\\Helper\\HelperInterface and/or callables.
Zend \\ View \\ HelperPluginManager只能创建Zend \\ View \\ Helper \\ HelperInterface和/或可调用对象的实例。
Is there any way to get the Application
context in my template (or better even the parameters of the URL)? 有什么方法可以在模板中获取
Application
上下文(甚至更好的是URL的参数)?
Your question title is "ZF3: Read out url parameter in PhpRenderer" while inside your question you asked another one. 您的问题标题是“ ZF3:在PhpRenderer中读出url参数”,而在您的问题中又问了一个。
You can get this in any controller (get URL parameters in ZF3): 您可以在任何控制器中获得它(在ZF3中获得URL参数):
$URLparam = (string)$this->params()->fromQuery('parameter', '');
For routeMatch, if you have a MvcEvent just use; 对于routeMatch,如果您有MvcEvent,请使用;
$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 如果要在视图中访问routeMatch,则除了tasmaniski / zend-current-route之类的视图助手外, 别无选择
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.