在Symfony2中更改SwiftMailer的tmp目录的位置 [英] Change the location of the tmp directory for SwiftMailer in Symfony2
问题描述
我的共享主机不允许我使用根\ tmp目录.
My shared hosting does not allow me to use the root \tmp directory.
我知道可以使用Swift_Preferences类来更新temp目录的位置,但是,对于由Symfony2自动加载的SwiftMailer实例,我该如何做呢?
I know that the location of the temp directory can be updated using the Swift_Preferences class, however, how do I do that for a SwiftMailer instance autoloaded by Symfony2?
是否可以在config.yml中设置它?
Is there a way to set it in my config.yml?
我认为代码应该是:
\ Swift_Preferences :: getInstance()-> setTempDir($ newTempDir);
\Swift_Preferences::getInstance()->setTempDir($newTempDir);
但是如何/在何处设置此配置?
But how/where can I set this config?
推荐答案
有多种方法可以做到这一点.但是,我认为最好的选择是在您的主"捆绑包的boot
方法内部.
There is more than a one way to do this. However, I think the best place for that would be inside boot
method of your "main" bundle.
.../My/WebsiteBundle/MyWebsiteBundle.php:
.../My/WebsiteBundle/MyWebsiteBundle.php:
...
public function boot() {
$tmpDir = $this->container->getParameter('my_website.swift_tmp_dir');
\Swift_Preferences::getInstance()->setTempDir($tmpDir);
}
...
这篇关于在Symfony2中更改SwiftMailer的tmp目录的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!