Check if in “dev” mode inside a Controller with Symfony

后端 未结 9 2157
無奈伤痛
無奈伤痛 2021-01-01 08:56

When using dev mode with a Symfony2.x application, one usually works in locale. Hence, such function does not works as expected (for instance, try to get th

9条回答
  •  一整个雨季
    2021-01-01 09:27

    For Symfony 4.x and above

    If you are using .env to store your environment variables, you can access them in any controller by simply using $_ENV['name-of-variable']

    For a default installation, there is a $_ENV["APP_ENV"] variable available, which will tell you if you are in dev mode or not.


    Use print_r($_ENV); to see all the available environment variables.

    [ps - This also works for Symfony 3.4]


    Reference - https://symfony.com/doc/4.3/components/dotenv.html

提交回复
热议问题