Reputation: 1246
In a form I am developing, I want to abandon changes and redirect to the same route if a submit button named ‘reset’ is pressed. The following code works for determining the current url and self-redirecting:
$hereandnow = $this->getRequest()->getRequestUri();
return $this->redirect()->toUrl($hereandnow);
I want to do the same using the route method:
return $this->redirect()->toRoute($current_route, $current_params);
// OR
return $this->redirect()->toRoute($current_route_including_params);
However, this requires a determination of the current route and parameters. How can I do that?
Upvotes: 2
Views: 576
Reputation: 1742
To answer you question, current matched route name is available in MVC event, in controller:
$this->getEvent()->getRouteMatch()->getMatchedRouteName();
matched route params:
$this->getEvent()->getRouteMatch()->getParams();
But, you can redirect to same URL (refresh page) in much simpler way:
return $this->redirect()->refresh();
Upvotes: 5