jcr*_*opp 2 redirect routes zend-framework2
在我正在开发的表单中,如果按下名为"reset"的提交按钮,我想放弃更改并重定向到相同的路由.以下代码用于确定当前URL和自重定向:
$hereandnow = $this->getRequest()->getRequestUri();
return $this->redirect()->toUrl($hereandnow);
Run Code Online (Sandbox Code Playgroud)
我想使用route方法做同样的事情:
return $this->redirect()->toRoute($current_route, $current_params);
// OR
return $this->redirect()->toRoute($current_route_including_params);
Run Code Online (Sandbox Code Playgroud)
但是,这需要确定当前路线和参数.我怎样才能做到这一点?
要回答你的问题,当前匹配的路由名称在MVC事件中,在控制器中可用:
$this->getEvent()->getRouteMatch()->getMatchedRouteName();
Run Code Online (Sandbox Code Playgroud)
匹配路线参数:
$this->getEvent()->getRouteMatch()->getParams();
Run Code Online (Sandbox Code Playgroud)
但是,您可以更简单的方式重定向到相同的URL(刷新页面):
return $this->redirect()->refresh();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
519 次 |
| 最近记录: |