Answer the question
In order to leave comments, you need to log in
Is it possible to change yml config file in symfony 4 with code?
Good time of the day, I have a yml config in my project which, for example, lies here
./config/packages/dev/parameters.yml
parameters:
var1: 'data1'
var2: 'data2'
$this->getContainer()->getParameter('var1');
$this->getContainer()->getParameter('var2');
parameters:
var1: 'data1'
var2: 'data2'
var3: 'data3'
$this->getContainer()->setParameter('var3','data3');
In srcApp_KernelDevDebugContainer.php line 1605:
Impossible to call set() on a frozen ParameterBag.
Answer the question
In order to leave comments, you need to log in
$this->getContainer()
1. If you are working with symphony 4.1+, then getting configuration parameters should be done using
Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class SomeClass{
private $params;
public function __construct(ParameterBagInterface $params)
{
$this->params = $params;
}
public function someMethod()
{
$parameterValue = $this->params->get('parameter_name');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question