在 UrlMatcher 类的帮助下,我在解析 URL 字符串并从中获取参数时遇到问题。
资源:
<?php
//RouteCollection
$routes = $this->container->get('routes');
//SubRequest to a Controller (POST)
$response = $this->forward(...);
if($response instanceof RedirectResponse){
//TargetUrl looks like this
//dev.php/admin/twitter-modul/1/show
//1 is the id of the Entity
$context = new RequestContext($response->getTargetUrl());
$matcher = new UrlMatcher($routes, $context);
//match throws a ResourceNotFoundException
$parameters = $matcher->match($response->getTargetUrl());
//Here i need the id paramater from the url
var_dump($parmeters);
}
return $response;
如何解析 URL-String 并从中获取参数?