-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Labels
BugHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.RoutingStatus: Needs Review
Description
Symfony version(s) affected: 4.3.3
Description
I am trying to force a parameter being set in a route using!
. It is working with the following annotation:
@Route("/titles/{!page}", name="list", methods={"GET"}, defaults={"page": 1})
When I generate the route without specifying a parameter ({{ path('list') }}
) the following path is generated: /titles/1
.
Unfortunately when combining !
with other short syntax elements it does not work as expected:
-
Specifying a default value using
?1
:@Route("/titles/{!page?1}", name="list", methods={"GET"})
produces:
/titles/%7B!page%3F1%7D
-
Specifying default as part of method signature:
/** * @Route("/titles/{!page}", name="list", methods={"GET"}) */ public function list(int $page = 1) { ... }
throws
Twig\Error\RuntimeError
:Some mandatory parameters are missing ("page") to generate a URL for route "list".
-
Specifying requirements for
page
using short syntax<\d+>
:@Route("/titles/{!page<\d+>}", name="list", methods={"GET"}, defaults={"page": 1})
produces:
/titles/%7B!page%3C%5Cd+%3E%7D
How to reproduce
- Install annotations
composer require annotations
- Create a template with a link to the route using the force parameter:
{{ path('...') }}
- Create a controller action rendering the template with the route link
- Create a controller action with one of the above route definitions containing
!
- Go to the initially defined route (template with link)
Metadata
Metadata
Assignees
Labels
BugHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.RoutingStatus: Needs Review