Symfony 4, get .env parameter from a controller, is it possible and how?

matthieu lopez picture matthieu lopez · Sep 3, 2018 · Viewed 18.8k times · Source

From symfony 4, I want create a global parameter and get the value of this parameter from a controller.

This parameter is the path of an another app in the server. So, I thinked add the paramerter in the .env file. But how can I get the value of this parameter from a controller?

Answer

Theva picture Theva · Nov 4, 2019

If someone is stil looking for the answer,

I was advised in a technical interview as the api credentials like token and key should be defined in .env

define your parameter in .env

MY_PARAM='my param value'

and then in controller call it

echo $_ENV['MY_PARAM'];