In Symfony4 they chose to replace the parameters.yml
with environment variables, as said in the docs and in the migration guides:
Define the infrastructure-related configuration options as environment variables. During development, use the .env file at the root of your project to set these.
I really don't like this change, I don't see any advantage but only drawbacks (for example we'd need to refactor the app because now only scalar values are allowed as environment variables, you can't host different installations in the same environment, etc...)
So my question is, is it possible to keep the old good parameters.yml file in Symfony4? How can I include this file and refer to his parameters, for example, in the doctrine.yml and swiftmailer.yml?
Done, it's very easy and it makes your migration to Symfony4 much easier.
Just move the parameters.yml
and parameters.yml.dist
to config/
, and rename them to .yaml for consistency.
Then add in services.yaml:
imports:
- { resource: parameters.yaml }
Then everything will remain the same, for example the doctrine.yaml file will be:
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
...
Optional: add https://github.com/Incenteev/ParameterHandler
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