-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add UrlHelper section to HttpFoundation docs #16176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Isn't the more accepted way to generate absolute URLs by using |
As far as I know, The use-case is different too. I use it to generate absolute images before I send them to Slack using the Symfony Notifier for example. Combined with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your code example, please:
- Change
Use
touse
, - At the top, add a file and namespace (
// src/Normalizer/UserApiNormalizer.php
andnamespace App\Normalizer;
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @dreadnip
components/http_foundation.rst
Outdated
$this->urlHelper = $urlHelper; | ||
} | ||
|
||
public function normalize($user, $format = null, array $context = []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function normalize($user, $format = null, array $context = []) | |
public function normalize($user): array |
as seems not used :)
do not know if we can typehint the $user tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
components/http_foundation.rst
Outdated
UrlHelper | ||
------- | ||
|
||
Generating absolute (and relative) URLs for a given path is a common need in lots of applications. In Twig templates this is trivial thanks to the absolute_url() and relative_path() functions. The same functionality can be found in the :class:`Symfony\\Component\\HttpFoundation\\UrlHelper` class, which can be injected as a service anywhere in your application. This class provides two public methods called getAbsoluteUrl() and getRelativePath():: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on sf doc, it is tried to keep lines to ~ 70/80 chars then go to new line :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d829020
to
5720f50
Compare
I was recently looking for a way to generate absolute URLs for assets in a service, and I finally stumbled upon the UrlHelper class after reading this blog post, but I couldn't find any mention of it in the docs when searching for absolute_url() or anything related.
I then saw this comment on the original PR, but saw no such PR for the docs.
This is my first contribution to the docs so any feedback is welcome.