1
1
1alexandr2015-06-14 18:21:39
symfony
1alexandr, 2015-06-14 18:21:39

How to change a parameter in Symfony2?

Hello! Tell me, please, how can I set the parameter specified in the yaml config

parameters:
    app_main.city: Анадырь

I try:
$this->container->setParameter('app_main.city', 'Канчалан')

but it gives me an error with the following content:
Impossible to call set() on a frozen ParameterBag.
Tell me what's wrong, please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2015-06-14
@1alexandr

And where are you trying to set the parameter? and must be set in the bundle configurator - in the DependencyInjection\YourBundleExtension class. After that, the container is frozen and cannot be changed. If you need it, then you are doing something wrong in the architecture.
If you need to change a parameter at the development level, put the desired value in parameters.yml (replace Anadyr with Kanchalan). And if the desired value is determined in the code, then it does not need to be set in the container parameter, it must be passed through the arguments of the service method.
Tell us in more detail what your task is, so that you can tell in more detail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question