From my controllers, I access the application parameters (those in /app/config
) with
$this->container->getParameter(\'my_param\')
<
With Symfony 4.1 the solution is quite simple.
Here is a snippet from the original post:
// src/Service/MessageGenerator.php
// ...
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class MessageGenerator
{
private $params;
public function __construct(ParameterBagInterface $params)
{
$this->params = $params;
}
public function someMethod()
{
$parameterValue = $this->params->get('parameter_name');
// ...
}
}
Link to the original post: https://symfony.com/blog/new-in-symfony-4-1-getting-container-parameters-as-a-service