How to get routing information from a relative url?

netteman
Member | 125
+
0
-

Hi all :)

let's say I have a relative URL like this /admin/article/detail/1

Can I somehow get information like this from the url?

[
	'module' => 'Admin',
	'presenter' => 'Article',
	'action' => 'detail',
	'id' => 1
]

I guess it's something like “reverse routing”

Thanks ;-)

Last edited by netteman (2019-11-22 15:36)

netteman
Member | 125
+
0
-

I figured this out:

/** @var \Nette\Http\Request @inject */
public $httpRequest;

...

$router = \App\RouterFactory::createRouter();

$urlScript = new \Nette\Http\UrlScript('/admin/article/detail/1');
$urlScript->setScriptPath($this->httpRequest->getUrl()->getScriptPath());

$request = new \Nette\Http\Request($urlScript);

bdump($router->match($request));

Is there another way how to get to the data returned by $router->match($request); ?

Thank you :)