I'm trying to get the current route name to be able to do some logic in the view. I need to retrieve this inside the view, not in the controller. For example, in laravel if I wanted to test for a route I would use Request::is('admin/dashboard')
or Route::current()->getName()
.
I've googled many times but I haven't found this answer anywhere.
In zend-expressive you can get the matched route from the route result .
$result = $request->getAttribute(RouteResult::class);
$routeName = $result->getMatchedRouteName();
From your action you can pass it into the view.
Some variables I always use and I inject those on every request by creating a wrapper around the TemplateRenderer .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.