-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Controller vs AbstractController difference #9991
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
Updates tip about difference between Controller and AbstractController.
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.
This plays well with #9989. Thanks!
container, using ``Controller`` is fine. | ||
You can extend either ``Controller`` or ``AbstractController``. The | ||
difference is that ``AbstractController`` is more strict and doesn't let you | ||
access services via ``$this->get()`` or ``$this->container->get()``. |
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.
and doesn't let you access services via
$this->get()
or$this->container->get()
.
Except for services defined in getSubscribedServices()
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.
Indeed. How can we improve this?
After reading Yonel's comment (#9991 (comment)) I'm starting to think that we should remove this note altogether. The On this introductory article, it could be better to focus on showing only |
I agree with @javiereguiluz, it's more confusing than useful. |
You're right, this tip is probably confusing for new comers. Thing is that the maker command make:controller, which is recommended in the Controller introduction article still generates a class extending Controller instead of AbstractController, which is in contradiction with best practices. But that has more to do with the maker command itself than with the documentation. |
@guillbdx yes ... we discussed about that in the Maker bundle repository. We didn't want to make the change until 4.1 was released, because AbstractController was missing the getParameter() shortcut. But now that the shortcut was added in 4.1, I think we can safely switch to AbstractController in the maker too. |
I'm closing this pull request for the reasons given above. Instead:
Thank you all for the discussion! |
…igher (javiereguiluz) This PR was squashed before being merged into the 1.0-dev branch (closes #221). Discussion ---------- Extend from AbstractController when using Symfony 4.1 or higher Related to symfony/symfony-docs#9991 ... let's extend from `AbstractController` when possible. Commits ------- 2e6403b Extend from AbstractController when using Symfony 4.1 or higher
Updates tip about difference between Controller and AbstractController.