Antoine Nedelec
Antoine Nedelec

Reputation: 665

Symfony4 - How to "setParameter"

I'm trying to use the

container->setParameter('abc','ABC')

to save a value in my "services.yaml", but everywhere I put that line it says i'm not allowed to do it when it's compiled.

How can I use it to store a value for the next runs ?

Upvotes: 0

Views: 763

Answers (1)

Nek
Nek

Reputation: 3105

You can set a parameter inside the container before it is compiled. It's designed to store configuration parameters. For example you can access kernel.project_dir parameter (and many others of this kind).

You can modify and add theses parameters in different places:

In any of theses cases, it happens before the container is compile (and cached for optimization purpose).


If you need some kind of parameter bag, you can use the attributes parameter of the Request (that have the advantage to be regenerate for subrequests in your code). You can also simply define your own parameter bag service.

Upvotes: 3

Related Questions