Skip to content

[FrameworkBundle] Document the AbstractController #7657

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

Merged
merged 3 commits into from
May 2, 2017

Conversation

GuilhemN
Copy link
Contributor

Document symfony/symfony#18193.
I'm not sure it should be merged right now though as it's an experimental feature.

\cc @dunglas

@HeahDude
Copy link
Contributor

@GuilhemN Would you like to document the abstract controller introduced in symfony/symfony#22157 instead? Thanks!

@GuilhemN
Copy link
Contributor Author

GuilhemN commented Mar 26, 2017

@HeahDude oh that's already merged, I didn't expect it to be so quick. I'll make the changes :)

@GuilhemN GuilhemN changed the title [FrameworkBundle] Document the ControllerTrait [FrameworkBundle] Document the AbstractController Mar 26, 2017
@GuilhemN
Copy link
Contributor Author

Updated to document the AbstractController instead.

ping @nicolas-grekas

@HeahDude
Copy link
Contributor

Closes #7705.

usually pretty easy and the base `Controller class source code`_ is a great
source on how to perform many common tasks.
In case you don't want to inject the container in your controllers,
it's possible to get ride of controller shortcut methods: you can interact
Copy link
Member

Choose a reason for hiding this comment

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

to get rid of (no "e")

# app/config/services.yml
services:
_instanceof:
Symfony\Bundle\FrameworkBundle\Controller\AbstractController:
Copy link
Member

Choose a reason for hiding this comment

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

this block is not needed, let's remove it from the doc

Copy link
Member

Choose a reason for hiding this comment

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

In fact, there is no config to do at all, an AbstractController doesn't need to be a service at all

Copy link
Contributor Author

@GuilhemN GuilhemN Mar 26, 2017

Choose a reason for hiding this comment

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

Do you think it should be documented in a different section then?

Imo its main usage is using controllers as a service and having access to the shortcuts.

Using the controller shortcuts
------------------------------

To use the traditional controller shortcuts, you can use the
Copy link
Member

@nicolas-grekas nicolas-grekas Mar 26, 2017

Choose a reason for hiding this comment

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

this paragraph is a bit strange to me, it doesn't really teach enough to the reader imho.
eg

if you prefer explicit injection (you can't access the container)

"why would I prefer explicit injection? esp when the words in the brackets suggest that this is less powerful, so let's just to the previous Controller." Which then raises "why did they tell me about this? do I miss anything?" leading to confusion.

my 2cts :)

@GuilhemN
Copy link
Contributor Author

Updated to document the AbstractController in the controller.rst file to not limit its use to controllers as services.

controller.rst Outdated
@@ -116,19 +116,26 @@ For more information on routing, see :doc:`/routing`.
.. index::
single: Controller; Base controller class

The Base Controller Class & Services
------------------------------------
The Base Controller Classes & Services
Copy link
Member

Choose a reason for hiding this comment

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

we should add a label for the old headline to not break any deep links

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, I'm not 100% sure this is how it works though.

@@ -241,10 +251,9 @@ are used for rendering templates, sending emails, querying the database and
any other "work" you can think of. When you install a new bundle, it probably
brings in even *more* services.

When extending the base controller class, you can access any Symfony service
When extending the base ``Controller`` class, you can access any Symfony service
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we're missing pros of using the new AbstractController, dependencies are explicit either in a constructor or in action signatures, but the controller needs to be configured to get injection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean we have to tell that the controller has to be configured as a service ? I updated the text to reflect that.

Copy link
Contributor

@HeahDude HeahDude Apr 7, 2017

Choose a reason for hiding this comment

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

Hmm it seems I got confused, reading @nicolas-grekas's comment above:

In fact, there is no config to do at all, an AbstractController doesn't need to be a service at all

The injection in this case is relying on an argument value resolver, so the controller does not need any configuration indeed.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I just said is wrong, the getters has nothing to do with action injections, so I don't get it, this must be configured somehow, it's just already done by the bundle.

@weaverryan weaverryan merged commit 4ac5da7 into symfony:master May 2, 2017
weaverryan added a commit that referenced this pull request May 2, 2017
…hemN)

This PR was squashed before being merged into the master branch (closes #7657).

Discussion
----------

[FrameworkBundle] Document the AbstractController

Document symfony/symfony#18193.
I'm not sure it should be merged right now though as it's an experimental feature.

\cc @dunglas

Commits
-------

4ac5da7 Fix
88a4806 Fix
cf2ae91 [FrameworkBundle] Document the AbstractController
@weaverryan
Copy link
Member

Thanks @GuilhemN! I'll merge this into my #7807 :)

The Base Controller Class & Services
------------------------------------
.. _anchor-name:
:ref:`The Base Controller Classes & Services <the-base-controller-class-services>`
Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar with this anchor-name thing - were you trying to make sure the old anchor still worked? If so, #7867 for an example. I'll update this in my PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that was a request from @xabbuh.
Thanks for the example, I never did that before and obviously didn't do it well by randomly trying :)

@GuilhemN GuilhemN deleted the CONTROLLER branch May 2, 2017 15:15
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.

6 participants