Skip to content

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
wants to merge 9 commits into from
Closed

Added shortcut methods for controllers #4109

wants to merge 9 commits into from

Conversation

Cydonia7
Copy link
Contributor

@Cydonia7 Cydonia7 commented Aug 8, 2014

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.

@stof
Copy link
Member

stof commented Aug 8, 2014

you should add ..versionadded:: 2.6, as new features can only be added in the next version (and given the timeframe, there is a high chance that it will not be postponed to 2.7)

@xabbuh
Copy link
Member

xabbuh commented Aug 8, 2014

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 :
Copy link
Member

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``

@xabbuh
Copy link
Member

xabbuh commented Aug 8, 2014

@Cydonia7 Besides these minor improvements, your pull request looks really good! 👍

fabpot added a commit to symfony/symfony that referenced this pull request Sep 19, 2014
…(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.
@xabbuh xabbuh changed the title [WCM] Added shortcut methods for controllers Added shortcut methods for controllers Sep 19, 2014
@xabbuh
Copy link
Member

xabbuh commented Sep 19, 2014

The code pull request has been merged.

and give it directly the route name like :

return $this->redirectToRoute('homepage');

Copy link
Member

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.

@weaverryan
Copy link
Member

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!

@Cydonia7
Copy link
Contributor Author

I think I can handle that :) Thanks for your help throughout the PRs!

fabpot added a commit to symfony/framework-bundle that referenced this pull request Sep 21, 2014
…(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.
@Cydonia7
Copy link
Contributor Author

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.

@Cydonia7
Copy link
Contributor Author

Any update on this ?

@xabbuh
Copy link
Member

xabbuh commented Oct 23, 2014

It would be better to add versionadded directives to not confuse people using older Symfony versions when reading the changed documents.

@@ -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::
Copy link
Member

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).

@weaverryan
Copy link
Member

Thanks @wouterj for the ping - this had fallen off of my radar. @Cydonia7 do you have some time to take a look at the notes I just added?

Thanks!

@Cydonia7
Copy link
Contributor Author

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
@Cydonia7
Copy link
Contributor Author

Cydonia7 commented Jan 4, 2015

@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).
Copy link
Member

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).

@Cydonia7
Copy link
Contributor Author

Cydonia7 commented Jan 4, 2015

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.
Copy link
Member

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.

@javiereguiluz
Copy link
Member

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?

@Cydonia7
Copy link
Contributor Author

What is needed to "complete" it ?

@weaverryan
Copy link
Member

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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see the example above)

@weaverryan
Copy link
Member

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 security.rst are too big. If you search for _book-security-securing-controller, you'll see that after your commits, there are 2 of these sections. This is due to a big refatoring of the security chapter, so it's my fault for making your life difficult.

Would you be able to rebase? The result should be that security.rst has less changes (i.e. it doesn't look like you added a new section).

Thanks!

@Cydonia7
Copy link
Contributor Author

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 ?

@xabbuh
Copy link
Member

xabbuh commented Feb 26, 2015

@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.

@Cydonia7
Copy link
Contributor Author

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.

@wouterj
Copy link
Member

wouterj commented Feb 26, 2015

Okay, I'll try :)

@Cydonia7
Copy link
Contributor Author

Thanks @wouterj, I didn't think I would have such a hard time rebasing this...

@stof
Copy link
Member

stof commented Feb 26, 2015

@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.

@wouterj
Copy link
Member

wouterj commented Feb 26, 2015

Closing in favor of #5046 (and indeed, it was a hell of a rebase, literally every change in this PR was conflicting...)

@wouterj wouterj closed this Feb 26, 2015
weaverryan added a commit that referenced this pull request Mar 14, 2015
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants