From cf8680dd25b4fbbe0173dc431e0555266d9d1cb0 Mon Sep 17 00:00:00 2001 From: guillbdx Date: Mon, 2 Jul 2018 02:36:17 +0200 Subject: [PATCH 1/2] Controller vs AbstractController difference Updates tip about difference between Controller and AbstractController. --- controller.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/controller.rst b/controller.rst index f520969667f..4439f937c91 100644 --- a/controller.rst +++ b/controller.rst @@ -146,11 +146,14 @@ and many others that you'll learn about next. .. tip:: - You can extend either ``Controller`` or ``AbstractController``. The difference - is that when you extend ``AbstractController``, you can't access services directly - via ``$this->get()`` or ``$this->container->get()``. This forces you to write - more robust code to access services. But if you *do* need direct access to the - container, using ``Controller`` is fine. + What's the difference between ``Controller`` or ``AbstractController``? Both + provide the same helper methods, but ``AbstractController`` is more strict: it + forces you to explicitly declare your dependencies before you can fetch them using + ``$this->get()`` or ``$this->container->get()``. This is considered a best practice + as ``Controller`` requires services to be public to do the same. But if you do + need direct access to the container, using Controller is fine. Learn more about + how to subscribe your services in the + :doc:`/service_container/service_subscribers_locators` article. .. versionadded:: 3.3 The ``AbstractController`` class was added in Symfony 3.3. From be2032288f3c3b986c2004e9c5ae8ca17d0a70f6 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 2 Jul 2018 11:26:38 +0200 Subject: [PATCH 2/2] Reword --- controller.rst | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/controller.rst b/controller.rst index 4439f937c91..ec21c20470c 100644 --- a/controller.rst +++ b/controller.rst @@ -146,14 +146,13 @@ and many others that you'll learn about next. .. tip:: - What's the difference between ``Controller`` or ``AbstractController``? Both - provide the same helper methods, but ``AbstractController`` is more strict: it - forces you to explicitly declare your dependencies before you can fetch them using - ``$this->get()`` or ``$this->container->get()``. This is considered a best practice - as ``Controller`` requires services to be public to do the same. But if you do - need direct access to the container, using Controller is fine. Learn more about - how to subscribe your services in the - :doc:`/service_container/service_subscribers_locators` article. + 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()``. + Instead, you must declare your dependencies explicitly with + :doc:`service locators `. + Using ``AbstractController`` is considered a best practice but if you do + need direct access to the container, using ``Controller`` is fine. .. versionadded:: 3.3 The ``AbstractController`` class was added in Symfony 3.3.