【问题标题】:Symfony 1.4.6 loading factories.yml configuration from taskSymfony 1.4.6 从任务加载 factory.yml 配置
【发布时间】:2011-04-02 17:21:09
【问题描述】:

我的 factory.yml 文件中设置了以下配置...

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

...克服here 所述的“双点”问题。

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

$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 使用的是默认传输类,而不是 factory.yml 配置中指定的 Swift_SendmailTransport 类。

任何想法为什么没有在 symfony 任务中加载 factory.yml 配置,以及我该如何解决这个问题?

【问题讨论】:

    标签: php configuration symfony1 yaml factories


    【解决方案1】:

    您的任务不知道要加载哪个应用程序的 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'),
      ));
    }
    

    【讨论】:

      猜你喜欢
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 2010-09-05
      相关资源
      最近更新 更多