use Symfony\Component\Routing\Generator\UrlGenerator; $generator = new UrlGenerator(/* ... */); $url = $generator->generate('route_name', ['param1' => 'value1', 'param2' => 'value2']); // Output: /route/path?param1=value1¶m2=value2 echo $url;
use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\RequestContext; $context = new RequestContext(/* ... */); $generator = new UrlGenerator(/* ... */, $context); $url = $generator->generate('route_name', ['param1' => 'value1'], UrlGenerator::ABSOLUTE_URL); // Output: http://example.com/route/path?param1=value1 echo $url;In this example, we use the UrlGenerator class again, but this time we pass in a RequestContext object to include the base URL of the website. We also use the ABSOLUTE_URL option to generate a complete URL with the protocol and domain. Package library: Symfony\Routing