Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/concepts/services/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ weight: 8

## Symfony Services

{{% notice warning %}}
**`$this->get()` resolves against the container of the context you are in, which is not always the full Symfony container.**

In the back office, and in pages already migrated to Symfony, you get the full container: `router`, `translator`
and anything you declared in `config/services.yml` are available. A front office page still runs a legacy
controller, and there `$this->get()` resolves against the light front container instead. It holds Doctrine and
the services declared in `<PS_ROOT_DIR>/config/services/front/`, and nothing else: asking it for `router` or
`translator` raises a `ServiceNotFoundException`, `$this->getTwig()` returns `null`, and
`SymfonyContainer::getInstance()` is `null` there too.

A service you want to call from a front office hook has to be declared in your module's `config/front/` folder.
See [Services in Legacy environment](#services-in-legacy-environment) below.
{{% /notice %}}

You have the ability to modify the Symfony container configuration from a module. This means that

- You have the possibility to define your own Symfony services from your modules.
Expand Down
Loading