-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Point that route parameters are also Request attributes #6219
Conversation
Point that route parameters are also Request attributes
@sfdumi 👍 I like your proposal because a lot of people are not aware of this. Thank you! |
{ | ||
// ... | ||
$titleAttribute = $request->attributes->get('title'); // same as $title |
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.
$titleAttribute
is confusing imo, to show this, its enough to write $request->attributes->get('title'); // same as $title
what do you thing @javiereguiluz
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.
I agree with you. We could even split the example in two parts:
// Getting the title via controller arguments
public function indexAction($page, $title)
{
// ...
}
// Getting the title via request attributes
use Symfony\Component\HttpFoundation\Request;
public function indexAction(Request $request)
{
$title = $request->attributes->get('title');
// ...
}
This sounds like a good idea. Should I update the PR? |
@@ -7,7 +7,7 @@ How to Pass Extra Information from a Route to a Controller | |||
Parameters inside the ``defaults`` collection don't necessarily have to | |||
match a placeholder in the route ``path``. In fact, you can use the | |||
``defaults`` array to specify extra parameters that will then be accessible as | |||
arguments to your controller: | |||
arguments to your controller, and as attributes of the ``Request`` object: |
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.
We change this a bit and only tell the reader that we can access the parameters in the controller:
[...] that will then be accessible in your controller::
I like this addition! If you can and agree with them, please update this PR to add the proposed changes. |
Separated the Request attributes example from the method argument one.
Updated the PR. |
👍 this PR looks ready to be merged. Our doc managers can fix some long lines when merging this. Thanks @sfdumi. |
👍 (I'm very sorry, the update comment completely slipped under my radar) |
…sfdumi) This PR was submitted for the 3.0 branch but it was merged into the 2.3 branch instead (closes #6219). Discussion ---------- Point that route parameters are also Request attributes Point that route parameters are also Request attributes Commits ------- 08aae4e Point that route parameters are also Request attributes
Thank you for these improvements @sfdumi! I have merged them into the |
* 2.3: [#6219] some tweaks Point that route parameters are also Request attributes [#6348] some minor tweaks [best practices] mostly typos [#6275] some minor tweaks [quick tour] mostly typos remove link-local IPv6 address (fe80::1) [#6305] move link reference to the bottom Mention IvoryCKEditorBundle in the Symfony Forms doc [#6328] minor tweak Update extension.rst - added caution box for people trying to remove the default file with services definitions Altered single / multiple inheritance sentence Replace XLIFF number ids by strings
* 2.7: [#6219] some tweaks Point that route parameters are also Request attributes [#6348] some minor tweaks [best practices] mostly typos [#6275] some minor tweaks [quick tour] mostly typos remove link-local IPv6 address (fe80::1) [#6305] move link reference to the bottom Mention IvoryCKEditorBundle in the Symfony Forms doc [#6328] minor tweak Update extension.rst - added caution box for people trying to remove the default file with services definitions Altered single / multiple inheritance sentence Replace XLIFF number ids by strings Rename DunglasApiBundle to ApiPlatform
* 2.8: [#6219] some tweaks Point that route parameters are also Request attributes [#6348] some minor tweaks [best practices] mostly typos [#6275] some minor tweaks [quick tour] mostly typos remove link-local IPv6 address (fe80::1) [#6305] move link reference to the bottom Mention IvoryCKEditorBundle in the Symfony Forms doc [#6328] minor tweak Update extension.rst - added caution box for people trying to remove the default file with services definitions Altered single / multiple inheritance sentence Replace XLIFF number ids by strings Rename DunglasApiBundle to ApiPlatform
* 3.0: [#6219] some tweaks Point that route parameters are also Request attributes [#6348] some minor tweaks [best practices] mostly typos Fix reference to app folder [#6275] some minor tweaks [quick tour] mostly typos remove link-local IPv6 address (fe80::1) [#6305] move link reference to the bottom Mention IvoryCKEditorBundle in the Symfony Forms doc [#6328] minor tweak Update extension.rst - added caution box for people trying to remove the default file with services definitions Altered single / multiple inheritance sentence Replace XLIFF number ids by strings Rename DunglasApiBundle to ApiPlatform
Point that route parameters are also Request attributes