Symfony 1.4.6加载工厂。
-
30-09-2019 - |
题
我的FORSIORY.YML文件中设置了以下配置。
all:
mailer:
param:
transport:
class: Swift_SendmailTransport
param:
command: /usr/sbin/sendmail -oi -t
...要克服“双点”问题,如上所述 这里.
当我运行以下代码...
$mailer = $this->getMailer();
$message = $mailer->compose();
$message->setTo('foo@bar.com');
$message->setFrom('foo@bar.com');
$message->setSubject('Testing');
$message->setBody(
$mailer->getRealtimeTransport()->getCommand(),
'text/plain'
);
$mailer->send($message);
...在动作中,一切都按预期工作。但是,当我从任务内部运行相同的代码时,我会遇到致命错误 - PHP Fatal error: Call to undefined method getCommand
- 因为SwiftMailer使用默认运输类,而不是 Swift_SendmailTransport
类似于Forcories.yml配置中的类。
有什么想法,为什么工厂不加载Symfony任务,以及如何解决此问题?
解决方案
您的任务不知道要加载哪个应用程序的工厂。即使您只有一个应用程序。您需要通过这样的应用程序参数:
php symfony namespace:task --application=frontend
要在任务中包含默认应用程序,请这样更新您的配置:
protected function configure()
{
$this->addOptions(array(
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'),
));
}
不隶属于 StackOverflow