开发者

Symfony 1.4.6 loading factories.yml configuration from task

I have the following configuration set in my factories.yml file...

all:
  mailer:
    param:
      transport:
        class: Swift_SendmailTransport
        param:
          command: /usr/sbin/sendmail -oi -t

...to overcome the 'double dot' issue as described here.

When I run the following code...

$mailer = $this->getMailer();
$message = $mailer->compose();

$message->setTo('foo@bar.com');
$message->setFrom('foo@bar.com');
$message->setSubject('Testing');开发者_Python百科
$message->setBody(
  $mailer->getRealtimeTransport()->getCommand(),
  'text/plain'
);

$mailer->send($message);

...inside an action everything works as expected. But when I run the same code from inside a task, I get a fatal error - PHP Fatal error: Call to undefined method getCommand - because SwiftMailer is using the default transport class and not the Swift_SendmailTransport class as specified in the factories.yml configuration.

Any ideas why the factories.yml configuration isn't loaded in a symfony task, and how I can go about solving this issue?


Your task doesn't know which application's factories.yml to load - even if you only have one app. You need to pass an application parameter like this:

php symfony namespace:task --application=frontend

To have a default app in your task, update your configure like this:

protected function configure()
{
  $this->addOptions(array(
    new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend'),
  ));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜