2014-05-01 119 views
0

我的共享主机不允许使用root \ tmp目录。在Symfony2中更改SwiftMailer的tmp目录的位置

我知道临时目录的位置可以使用Swift_Preferences类来更新,但是,我如何为由Symfony2自动加载的SwiftMailer实例做到这一点?

有没有办法在我的config.yml中设置它?

我认为代码应该是:

\ Swift_Preferences ::的getInstance() - > setTempDir($ newTempDir);

但是,如何/在哪里可以设置此配置?

回答

-1

您可以通过autoprepend.php脚本修改整个参数:

<?php 
putenv('TMPDIR=/var/www/yourdir/tmp'); 

,并在您的文档根目录设置在.htaccess:

php_value auto_prepend_file /var/www/yourdir/htdocs/autoprepend.php 
+0

我想使我的项目中的变化非常。而不是依靠系统配置。 –

+0

.htaccess应该保留在您的项目目录中。主要优点是,这会修改每个依赖于['sys_get_temp_dir()'](http://us.php.net/sys_get_temp_dir)的库的tmp目录,而不仅仅是swiftmailer。 –

1

有比单向更多去做这个。不过,我认为最好的地方应该在你的“主要”套餐的boot方法中。

... /我的/ WebsiteBundle/MyWebsiteBundle.php:

... 

public function boot() { 
    $tmpDir = $this->container->getParameter('my_website.swift_tmp_dir'); 

    \Swift_Preferences::getInstance()->setTempDir($tmpDir); 
} 

...