You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide a service for generating a route by its route-name
Q
A
New Feature
yes
Summary
// src/Service/SomeService.phpnamespaceApp\Service;
useSymfony\Component\Routing\Generator\UrlGeneratorInterface;
class SomeService
{
publicfunction__construct(
privateUrlGeneratorInterface$router,
) {
}
publicfunctionsomeMethod(): void
{
// ...// generate a URL with no route arguments$signUpPage = $this->router->generate('sign_up');
// generate a URL with route arguments$userProfilePage = $this->router->generate('user_profile', [
'username' => $user->getUserIdentifier(),
]);
// generated URLs are "absolute paths" by default. Pass a third optional// argument to generate different URLs (e.g. an "absolute URL")$signUpPage = $this->router->generate('sign_up', [], UrlGeneratorInterface::ABSOLUTE_URL);
// when a route is localized, Symfony uses by default the current request locale// pass a different '_locale' value if you want to set the locale explicitly$signUpPageInDutch = $this->router->generate('sign_up', ['_locale' => 'nl']);
}
}
Feature Request
Provide a service for generating a route by its route-name
Summary
https://symfony.com/doc/current/routing.html#generating-urls-in-services
The text was updated successfully, but these errors were encountered: