質問

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