Symfony 1.4.6 从任务加载factories.yml配置

发布于 2024-09-16 02:44:33 字数 1198 浏览 2 评论 0原文

我在 Factory.yml 文件中设置了以下配置...

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

...以克服描述的“双点”问题 此处

当我运行以下代码时...

$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);

...在操作内一切都按预期工作。但是,当我从任务内部运行相同的代码时,出现致命错误 - PHP Fatal error: Call to undefined method getCommand - 因为 SwiftMailer 使用的是默认传输类,而不是 Swift_SendmailTransport 类在factories.yml 配置中指定。

知道为什么 Factory.yml 配置没有加载到 symfony 任务中,以及如何解决这个问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绅士风度i 2024-09-23 02:44:44

您的任务不知道要加载哪个应用程序的factory.yml - 即使您只有一个应用程序。您需要传递这样的应用程序参数:

php symfony namespace:task --application=frontend

要在您的任务中拥有默认应用程序,请像这样更新您的配置:

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

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'),
  ));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文