Closed mazhuravlev closed 7 years ago
Should be "True or false ? path() Twig function generates absolute paths ."
Good luck with the certification ! :)
Thank you!
The problem is path() can generate both relative and absolute paths. The question can be
What Twig path() function does generate?
- absolute path (true)
- relative path (true)
- absolute url (false)
Also the difference between url and path is very subtle (RFC 1808 has URL BNF)
URL = ( absoluteURL | relativeURL )
absoluteURL = generic-RL | ( scheme ":" *( uchar | reserved ) )
generic-RL = scheme ":" relativeURL
relativeURL = net_path | abs_path | rel_path
abs_path = "/" rel_path
rel_path = [ path ] [ ";" params ] [ "?" query ]
path = fsegment *( "/" segment )
fsegment = 1*pchar
segment = *pchar
If we look at docs, path()
sounds recommended to generate relative urls/paths when url()
is recommended for absolute urls.
In my opinion this is a mistake, and path()
should be avoided and url()
always used instead.
How about:
True or false ? url() function generates absolute urls by default.
- true (true)
- false (false)
What do you think ?
I will study if there is any need for relative urls at all in web applications and then make a pull request.
Ok, I close the issue for now.
Don't hesitate to make a pull request if you think it's worth :)
Question : True or false ? path() Twig function generates absolute urls.
According to source, RoutingExtension::path() generates not urls, but paths, and those are absolute by default, but can be made relative by setting the third parameter true. Signature of the helper is:
path($name, $parameters = array(), $relative = false)