Skip to content

Commit 2713169

Browse files
committed
minor #12617 Update best_practices.rst (amine-betari)
This PR was squashed before being merged into the 4.3 branch (closes #12617). Discussion ---------- Update best_practices.rst // there is a public "router" service in the container $router = $this->container->get('router'); // this will not Work: MailLogger is a private service $mailLogger = $this->container->get(MailLogger::class); Commits ------- fcddead Update best_practices.rst
2 parents 377d585 + fcddead commit 2713169

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

best_practices.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ the fact that a controller should always return a ``Response`` object.
234234
Use Dependency Injection to Get Services
235235
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
236236

237-
If you extend the base ``AbstractController``, you can't access services
238-
directly from the container via ``$this->container->get()`` or ``$this->get()``.
237+
If you extend the base ``AbstractController``, you can only access to the most common services (e.g ``twig``, ``router``, ``doctrine``, etc.), directly from the container via ``$this->container->get()`` or ``$this->get()``.
239238
Instead, you must use dependency injection to fetch services by
240239
:ref:`type-hinting action method arguments <controller-accessing-services>` or
241240
constructor arguments.

0 commit comments

Comments
 (0)