I have put a couple of custom variables in my app/config/parameters.yml.
parameters:
api_pass: apipass
api_user: apiuser
I need to
In Symfony 4, you can use the ParameterBagInterface:
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');
// ...
}
}
and in app/config/services.yaml:
parameters:
locale: 'en'
dir: '%kernel.project_dir%'
It works for me in both controller and form classes. More details can be found in the Symfony blog.