I added this to my .env
:
PHOTOS_DIR=%kernel.project_dir%/var/photos
Of course, when I try to retrieve the value of $_ENV['PHOTOS_DIR']
, I get the raw string %kernel.project_dir%/var/photos
.
But how can I get the value processed by the Symfony config processor, e.g. /my/project/var/photos
?
EDIT:
I'm aware that it is simply possible to add this in services.yaml
:
parameters:
photos_dir: '%kernel.project_dir%/var/photos'
But I would like to keep important config data in the .env
file.
You can set default values for environment variables using a .env file, which Compose automatically looks for in project directory (parent folder of your Compose file). Values set in the shell environment override those set in the .env file.
You can create a . env file at the root of the project directory and put the credential in the file. You can also choose to store your environment variables within a virtual environment; the environment variables will be accessible once the virtual environment is activated.
env. example file documents the application's necessary variables and can be committed to version control. This serves as a helpful reference and speeds up the onboarding process for new team members by reducing the amount of time spent digging through the coding to figure out what needs to be set up.
In order to expand %kernel.project_dir%
, use %env(resolve:...)
in parameters, e.g.:
parameters:
photos_dir: '%env(resolve:PHOTOS_DIR)%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With