【问题标题】:Swift_SmtpTransport phalconSwift_SmtpTransport phalcon
【发布时间】:2016-10-23 13:54:05
【问题描述】:

我正在尝试使用依赖注入器在 Phalcon 3 上加载 SwiftMailer,但我收到有关 Swift_transporter 服务的错​​误。

Phalcon\Di\Exception:在依赖注入容器中找不到服务“\Swift_SmtpTransport”

我想知道如何在依赖注入器中加载 Swift_SmtpTransport 服务,无需作曲家。我知道composer可以轻松解决这个问题,但我想知道是否还有其他选择。

在我的 service.php 文件中,我添加了下一行:

$di->set('mailer', function(){

$mailer = new Manager([
    'driver'   => 'sendmail',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'viewsDir' => $this->config->application->viewsDir . 'emails/',
    'from'     => [
        'email' => 'notify@website.com',
        'name'  => 'Company Team'
    ]
]);

return $mailer;

});

然后我用下一行调用服务:

$this->mailer([
        'to'      => 'email@test.com',
        'name'    => 'First and Last Name',
        'subject' => _('Welcome to my website'),
        'body'    => [
            'view'   => 'welcome',
            'params' => [
                'name' => 'First Name',
                'link' => $this->url->get('users/activate/?email=email@test.com&activation_key=******')
            ]
        ]
    ]);

【问题讨论】:

    标签: php dependency-injection phalcon swiftmailer


    【解决方案1】:

    在 phalcon 3.0 中添加了名为 loadFile 的新方法 do phalcon loader。只需将它与swift_required.php 路径一起使用

    【讨论】:

    • 你好朱里!感谢您的回复
    【解决方案2】:

    现在我了解了 Phalcon 孵化器的工作原理。如果有人在没有 composer 的情况下安装 Incubator 必须考虑到孵化器中的某些库需要外部库。为此,如果你通过克隆Github仓库的方式安装Incubator,并且不执行composer update,则必须一一加载外部库的所有依赖。

    【讨论】:

    • 或者只是用 phalcon loader 注册整个目录或命名空间:)
    • 我的结构中没有任何供应商文件夹,我应该如何解决同样的问题
    猜你喜欢
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2013-09-27
    • 1970-01-01
    相关资源
    最近更新 更多