views:

65

answers:

1

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('[email protected]');
$message->setFrom('[email protected]');
$message->setSubject('Testing');
$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?

+1  A: 

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'),
  ));
}
Maerlyn
Wonderful, thank you kindly!
Martin Chatterton