gpt4 book ai didi

Symfony4 - 选择退出 "environment variables"功能并保留旧的 parameters.yml 文件?

转载 作者:行者123 更新时间:2023-12-05 00:49:02 25 4
gpt4 key购买 nike

在 Symfony4 中,他们选择替换 parameters.yml带有环境变量,如 docs 中所述并在迁移指南中:

Define the infrastructure-related configuration options as environment variables. During development, use the .env file at the root of your project to set these.



我真的不喜欢这种变化,我看不到任何优点,只有缺点(例如,我们需要重构应用程序,因为现在只允许标量值作为环境变量,您不能在相同的环境等...)

所以我的问题是,是否可以在 Symfony4 中保留旧的好 parameters.yml 文件?我怎样才能包含这个文件并引用他的参数,例如,在doctrine.yml 和swiftmailer.yml 中?

最佳答案

完成了,这很容易,而且它使您迁移到 Symfony4 变得更加容易。

只需移动 parameters.ymlparameters.yml.distconfig/ ,并将它们重命名为 .yaml 以保持一致性。

然后在services.yaml中添加:

imports:
- { resource: parameters.yaml }

然后一切都将保持不变,例如 doctic.yaml 文件将是:
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
...

可选:添加 https://github.com/Incenteev/ParameterHandler

关于Symfony4 - 选择退出 "environment variables"功能并保留旧的 parameters.yml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48362420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com