-
-
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
Conversation
you should add |
Actually, this isn't a bug fix but a new feature. So, the pull request description would usually look something like this: | Q | A
| ------------- | ---
| Doc fix? | no
| New docs? | yes (symfony/symfony#11593)
| Applies to | 2.6+
| Fixed tickets | |
@@ -451,6 +451,10 @@ perform a 301 (permanent) redirect, modify the second argument:: | |||
|
|||
return new RedirectResponse($this->generateUrl('homepage')); | |||
|
|||
You can also directly use ``redirectToRoute()`` and give it directly the route name like : |
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.
You can link directly to the API docs (instead of redirectToRoute()
):
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller::redirectToRoute``
@Cydonia7 Besides these minor improvements, your pull request looks really good! 👍 |
…(Cydonia7) This PR was merged into the 2.6-dev branch. Discussion ---------- [FrameworkBundle] Add shortcut methods to controllers | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11166 | License | MIT | Doc PR | symfony/symfony-docs#4109 To-do list : - [x] submit changes to the documentation Added redirectToRoute, addFlash, isGranted and checkGranted to controllers. The code seems so simple I didn't feel like adding controller tests was needed since we're just shortcuting other services calls. Commits ------- 74d8c9a Add redirectToRoute, addFlash, isGranted and denyAccessUnlessGranted shortcuts to controllers.
The code pull request has been merged. |
and give it directly the route name like : | ||
|
||
return $this->redirectToRoute('homepage'); | ||
|
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 the versionadded
, we can say something like:
.. versionadded:: 2.6
The ``redirectToRoute()`` shortcut method was added in Symfony 2.6. The longer way, which
involves using `generateUrl()` and creating a
:class:`Symfony\\Component\\HttpFoundation\\RedirectResponse` object, still works like before.
Hey Thomas! Congrats on getting the PR merged into core - I was very excited about it! The docs PR actually needs to be much more involved. As I've commented, instead of just mentioning the new methods, I'd like to actually use the new methods through the docs and not use the old ways. This means that this PR is quite a bit more difficult. If you want to try updating everything, awesome! If you'd rather have one of the core contributors take over this PR, that's no problem :). Thanks! |
I think I can handle that :) Thanks for your help throughout the PRs! |
…(Cydonia7) This PR was merged into the 2.6-dev branch. Discussion ---------- [FrameworkBundle] Add shortcut methods to controllers | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11166 | License | MIT | Doc PR | symfony/symfony-docs#4109 To-do list : - [x] submit changes to the documentation Added redirectToRoute, addFlash, isGranted and checkGranted to controllers. The code seems so simple I didn't feel like adding controller tests was needed since we're just shortcuting other services calls. Commits ------- 74d8c9a Add redirectToRoute, addFlash, isGranted and denyAccessUnlessGranted shortcuts to controllers.
After changing so much documentation, I have to admit I am quite surprised about how many times it was used throughout the docs but here it is, I think I am done with this PR. Waiting for your feedback. |
Any update on this ? |
It would be better to add |
@@ -423,28 +423,24 @@ to manage in Symfony2. | |||
Redirecting | |||
~~~~~~~~~~~ | |||
|
|||
If you want to redirect the user to another page, use the ``redirect()`` method:: | |||
If you want to redirect the user to another page, use the ``redirectToRoute()`` method:: |
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 need a versionadded:: 2.6 block above this:
.. versionadded:: 2.6
The ``redirectToRoute()`` method was added in Symfony 2.6. Previously (and still now), you
could use ``redirect()`` and ``generateUrl()`` together for this (see the example below).
I will give it a look when I come home in a few days. Thanks @weaverryan ! |
Conflicts: book/controller.rst book/security.rst cookbook/security/remember_me.rst cookbook/security/securing_services.rst quick_tour/the_controller.rst
@weaverryan I think I've changed it all, would you please take a look? |
.. versionadded:: 2.6 | ||
The ``denyAccessUnlessGranted()`` method was introduced in Symfony 2.6. Previously (and | ||
still now), you could check access directly and throw the ``AccessDeniedException`` as shown | ||
in the example below). |
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 would move it above the paragraph (right below the "Securing a Controller" headline).
I fixed the issues @xabbuh @javiereguiluz |
the one seen in the previous section. For example, suppose you have a service | ||
(i.e. a PHP class) whose job is to send emails from one user to another. | ||
You can restrict use of this class - no matter where it's being used from - | ||
to users that have a specific role. |
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.
The following code block doesn't really belong to this paragraph.
Could we made a final effort to complete this PR? It would be nice to show and use the new shortcuts, but I understand that the PR is so big and complex that is taking forever to complete :( If there is much work to do, could we create another separate PR? |
What is needed to "complete" it ? |
Ah, we're clearly waiting on me only! I'll put this on my primary list and so will review and merge very soon. Sorry for being in the way here! |
chapter. | ||
.. versionadded:: 2.6 | ||
The ``redirectToRoute()`` method was added in Symfony 2.6. Previously (and still now), you | ||
could use ``redirect()`` and ``generateUrl()`` together for this (see the example below). |
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.
(see the example above)
Hey @Cydonia7! Sorry for the delay on my end. I just need one more thing from you. I added a really easy comment, but what I really need is a rebase. I need to merge this into the 2.6 branch, which is conflicting in the security chapter. You can kind of see it here - the changes to Would you be able to rebase? The result should be that Thanks! |
I tried and didn't manage to do it for now... The rebase is so complex I can't even understand what I am doing sometimes (I've had to do like 5 times rebase --continue and changing commits I didn't even authored). So what should I do ? |
@Cydonia7 If you were able to join #symfony-docs on IRC, someone could probably be able to help you. Otherwise, if you don't mind, we can take your changes, rebase them and create a new PR for you. |
I won't have time during the next week to do this but I don't mind, you can create a new PR with my changes. |
Okay, I'll try :) |
Thanks @wouterj, I didn't think I would have such a hard time rebasing this... |
@Cydonia7 if you are changing commits you have not authored, it means you are doing the wrong rebase. You should rebase your own feature branch, not the symfony branch. |
Closing in favor of #5046 (and indeed, it was a hell of a rebase, literally every change in this PR was conflicting...) |
This PR was merged into the 2.6 branch. Discussion ---------- Rebased "add shortcut methods" Replaces #4109 Original Pr description: > | Q | A > | ------------- | --- > | Doc fix? | no > | New docs? | yes (symfony/symfony#11593) > | Applies to | 2.6+ > | Fixed tickets | #4666 > > This commit is associated to symfony/symfony#11593 that adds new shortcut methods to controllers. > > If anything is wrong with my commit or this description, please tell me and I will fix it as soon as possible. I'm glad I finally try to help this awesome project. Commits ------- 994ed3a Little fixes f807d14 Fixes 5b015f2 Modifications according to comments 7f9bc8c And now the same for isGranted where it is possible 46e2505 Changed to addFlash where it is possible (ie in controllers) 643c458 redirect changed to redirectToRoute 7ae62e8 Minor improvements 4611ce9 Minor format improvements 3bcb186 Added shortcut methods for controllers
This commit is associated to symfony/symfony#11593 that adds new shortcut methods to controllers.
If anything is wrong with my commit or this description, please tell me and I will fix it as soon as possible. I'm glad I finally try to help this awesome project.