문제

I'm use Symfony2.3 and have a route named my_route with path /my/test/path/{param1}.

If I try to generate URL for this route, I'll write something like this:

/** @var Symfony\Bundle\FrameworkBundle\Routing\Router **/
$router = ...;
$router->generate('my_route', array('param1' => 'value1')); // /my/test/path/value1

But, if I use a non-exists parameter in generate method, URL becomes /my/test/path/value1?param2=value2:

$router->generate('my_route', array('param1' => 'value1', 'param2' => 'value2')); // /my/test/path/value1?param2=value2

How can I check if param2 exists in route?

도움이 되었습니까?

해결책

Have a look into the class "Symfony\Component\Routing\Route".

$route = $this->get('router')->getRouteCollection()->get('my_route');
$pathVariables = $route->compile()->getPathVariables()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top