I always tend to forget these built-in Symfony functions for making links.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your goal is to have user-friendly URLs throughout your application, use the following approach:
1) Create a routing rule for your module/action in the application’s routing.yml file. The following example is a routing rule for an action that shows the most recent questions in an application, defaulting to page 1 (using a pager):
2) Once the routing rule is set, use the
url_for()helper in your template to format outgoing URLs.In this example, the following URL will be constructed:
http://myapp/questions/recent/1.html.3) Incoming URLs (requests) will be analyzed by the routing system, and if a pattern match is found in the routing rule configuration, the named wildcards (ie. the
:/pageportion of the URL) will become request parameters.You can also use the
link_to()helper to output a URL without using the HTML<a>tag.