Question

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?

Was it helpful?

Solution

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

$route = $this->get('router')->getRouteCollection()->get('my_route');
$pathVariables = $route->compile()->getPathVariables()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top