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
From Symfony 4.1 inside Service
class MyService
{
private $params;
public function __construct(ParameterBagInterface $params)
{
$this->params = $params;
}
public function check($e)
{
if($this->params->get("kernel.environment") === "dev")
{
return true;
}
}
}
To get the current environment in a Controller you can use:
$this->container->getParameter('kernel.environment');
So you just put that in an if() statement to check if it equals to dev.
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