nullwriter
nullwriter

Reputation: 804

Get current route name in the view in Zend Expressive?

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.

Upvotes: 0

Views: 683

Answers (1)

user2408230
user2408230

Reputation:

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.

Upvotes: 2

Related Questions