slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.98k stars 1.95k forks source link

Slim3 app->router()->getCurrentRoute() #1644

Closed mbretter closed 8 years ago

mbretter commented 8 years ago

Hi,

during the migration from Slim2 => 3, I have not found a way in slim3 to get the current Route, in slim2 it was $app->router()->getCurrentRoute()

thx, cheers

silentworks commented 8 years ago

Take a look here https://github.com/slimphp/Slim/issues/1594#issuecomment-157010524

geggleto commented 8 years ago

$request->getAttribute('route')

mbretter commented 8 years ago

thx!

mbretter commented 8 years ago

If you are accessing this attribute within an app middleware it's important to set 'determineRouteBeforeAppMiddleware' => true, otherwise $request->getAttribute('route') returns null

lexakozakov commented 8 years ago

@silentworks Thank you, man. Finally I got it.

lexakozakov commented 8 years ago

Set in the app config - 'determineRouteBeforeAppMiddleware' => true

$request->getAttribute('route')->getName()
Motard commented 7 years ago

I am having some trouble with this. I am getting null when i do $request->getAttribute('route')->getName(). And I have also the determineRouteBeforeAppMiddleware' => true in the settings.php.

Anyone has any suggestion?

akrabat commented 7 years ago

@Motard The Url hasn't matched or you haven't called ->setName() after you defined your route.

Motard commented 7 years ago

Thx @akrabat. The problem was the missing ->setName() after declaring the route.