-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added shortcut methods for controllers #4109
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ccc6384
Added shortcut methods for controllers
Cydonia7 3b03455
Minor format improvements
Cydonia7 675877d
Minor improvements
Cydonia7 0366a0c
redirect changed to redirectToRoute
Cydonia7 8b23729
Changed to addFlash where it is possible (ie in controllers)
Cydonia7 4a54c5f
And now the same for isGranted where it is possible
Cydonia7 cded08b
Merge branch 'master' into add-shortcut-methods
Cydonia7 6db9c11
Modifications according to comments
Cydonia7 0758d62
Fixes
Cydonia7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -451,6 +451,13 @@ perform a 301 (permanent) redirect, modify the second argument:: | |
|
||
return new RedirectResponse($this->generateUrl('homepage')); | ||
|
||
.. versionadded:: 2.6 | ||
You can also directly use | ||
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller::redirectToRoute` | ||
and give it directly the route name like : | ||
|
||
return $this->redirectToRoute('homepage'); | ||
|
||
.. index:: | ||
single: Controller; Forwarding | ||
|
||
|
@@ -720,6 +727,10 @@ After processing the request, the controller sets a ``notice`` flash message | |
and then redirects. The name (``notice``) isn't significant - it's just what | ||
you're using to identify the type of the message. | ||
|
||
.. versionadded:: 2.6 | ||
You can use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::addFlash` | ||
method as a shortcut to ``$this->get('session')->getFlashBag()->add(...)``. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here - we should replace all the old code with the new |
||
In the template of the next action, the following code could be used to render | ||
the ``notice`` message: | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1124,6 +1124,12 @@ Thanks to the SensioFrameworkExtraBundle, you can also secure your controller us | |
For more information, see the | ||
:doc:`FrameworkExtraBundle documentation </bundles/SensioFrameworkExtraBundle/annotations/security>`. | ||
|
||
.. versionadded:: 2.6 | ||
You can use directly :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::isGranted` | ||
instead of `$this->get('security.context')->isGranted($role)` to check if | ||
a role is granted and :method:`Symfony\\Bundle\\FrameworkBundle\\Controller::denyAccessUnlessGranted` | ||
to throw an exception if the access is not granted (like in the example above). | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And same here, let's use the shortcut methods everywhere |
||
Securing other Services | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think that we should replace all
$this->redirect
with this new$this->redirectToRoute
. I want to show people the easiest way of doing things. In theversionadded
, we can say something like: