我已将我的symfony应用程序部署到Heroku,但我想使用Heroku提供的config_vars配置swiftmailer组件。我已经有两个了:
现在我想做的是在config_prod.yml中描述swiftmailer凭据:
#config_prod.yml
swiftmailer:
transport: "%env(mail_transport)%"
host: "%env(mail_host)%"
username: "%env(mail_user)%"
password: "%env(mail_password)%"
spool: { type: memory }
然后,我在Heroku上设置了config_vars,但是在尝试部署应用程序时,我得到了以下异常。
[Symfony\Component\DependencyInjection\Exception\EnvParameterException]
Incompatible use of dynamic environment variables "mail_transport" found in parameters.
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
Unable to replace alias "swiftmailer.mailer.default.transport.real" with actual definition "%env(mail_transport)%".
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
You have requested a non-existent service "%env(mail_transport)%".
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
如果我在config.yml中对参数进行硬编码,那么部署到Heroku会成功。
我搞砸了什么? Thx提前。
答案 0 :(得分:0)
我对heroku知之甚少,但我知道如何在symfony配置中获取ENV_VAR;)
你的其他配置文件所在的app/config
内的会创建一个名为parameters.php
的新文件
<?php
if(isset($_SERVER['AWS_MAILER_HOST']) ){
$container->setParameter('mailer_transport', @$_SERVER['AWS_MAILER_TRANSPORT']);
$container->setParameter('mailer_host', @$_SERVER['AWS_MAILER_HOST']);
$container->setParameter('mailer_username', @$_SERVER['AWS_MAILER_USERNAME']);
$container->setParameter('mailer_password', @$_SERVER['AWS_MAILER_PASSWORD']);
$container->setParameter('mailer_port', @$_SERVER['AWS_MAILER_PORT']);
$container->setParameter('mailer_encryption', @$_SERVER['AWS_MAILER_ENCRYPTION']);
$container->setParameter('mailer_auth_mode', @$_SERVER['AWS_MAILER_AUTH_MODE']);
}
用'AWS_MAILER_...'
ENVIRONEMENT_VAR
在app/config/config.yml
放置
imports:
- { resource: parameters.yml }
- { resource: parameters.php } <------------