Reputation: 583
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?
Upvotes: 1
Views: 1528
Reputation: 46
Have a look into the class "Symfony\Component\Routing\Route".
$route = $this->get('router')->getRouteCollection()->get('my_route');
$pathVariables = $route->compile()->getPathVariables()
Upvotes: 3