I got defined routes in routing.yml file
one route is:
Profile_user_profile:
path: /profile/{id}
defaults: { _controller: ProfileBundle:Users:profile }
methods: [get]
and second is:
Profile_accept_connection_proposal:
path: /profile/acceptProposal
defaults: { _controller:ProfileBundle:Users:acceptConnectionProposal }
methods: [put]
First route without methods: [get] listen also and [put] request and catch second url before it get to route definition. Is there way to define checking for parameter only if url is numeric.
This tutorial provides 2 methods how to get route parameters in Symfony 6 application. The Request object contains route configuration which stored in the public attributes property. It is an instance of ParameterBag. The get method can be used to retrieve route parameters from attributes property by _route_params key.
Symfony includes some commands to help you debug routing issues. First, the debug:router command lists all your application routes in the same order in which Symfony evaluates them: Pass the name (or part of the name) of some route to this argument to print the route details:
} } When using PHP attributes for localized routes, you have to use the path named parameter to specify the array of paths. When a localized route is matched, Symfony uses the same locale automatically during the entire request.
Symfony defines some special controllers to render templates and redirect to other routes from the route configuration so you don't have to create a controller action. Read the section about rendering a template from a route in the main article about Symfony templates. Use the RedirectController to redirect to other routes and URLs:
Just add the requirements
parameter to accept only digits for a determined route like this:
Profile_user_profile:
path: /profile/{id}
defaults: { _controller: ProfileBundle:Users:profile }
methods: [get]
requirements: <--- ADDED PARAMETER
id: \d+
For more infos read the Symfony book about Routing. There you can find more advanced example on how to use route parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With