简体   繁体   English

允许用户从.env Symfony修改一些参数

[英]Allow the user to modify some parameters from .env Symfony

I have some config variables on the .env file. 我在.env文件上有一些配置变量。 I want to create a page on my web application to allow the administrators to modify the value of some .env variables (for example the mail configured to send mails). 我想在Web应用程序上创建一个页面,以允许管理员修改某些.env变量的值(例如,配置为发送邮件的邮件)。 For this purpose, I have: 为此,我有:

MAILER_SENDER_ADDRESS=backoffice@example.com
MAILER_SENDER_NAME="Application Name"
MAILER_URL=gmail://firstname.lastname@gmail.com:ijfxxiencrrdqihe@localhost

I am able to read the current values on my controller but I don't know how to save back the values filled by the user on my form. 我能够读取控制器上的当前值,但是不知道如何保存用户在表单上填写的值。

Please, any help would be really apreciated. 请,任何帮助将不胜感激。

Environment variables are there to help you specify variables for the particular environment your application runs on, for example you could have your app sitting locally on your computer which you develop on, and you could have it in the cloud running the production version of your app, version which will actually send emails correctly using real data. 环境变量可以帮助您为运行应用程序的特定环境指定变量,例如,您可以将应用程序本地放置在要开发的计算机上,也可以将其放置在运行应用程序生产版本的云中,该版本实际上将使用真实数据正确发送电子邮件。

What you need to do is have somewhere to store the settings you let your users customise, for example in a database. 您需要做的是在某个地方存储让用户自定义的设置,例如在数据库中。 When it comes to sending the emails, you will then have to do the following: 在发送电子邮件时,您将必须执行以下操作:

$message = (new Swift_Message())
->setFrom(['john@doe.com' => 'John Doe'])
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM