【问题标题】:Twig Swiftmailer without Symfony没有 Symfony 的 Twig Swiftmailer
【发布时间】:2016-06-15 13:19:44
【问题描述】:

我正在尝试使用 Standalone Twig 通过 Swiftmailer 发送电子邮件。我在“使用纯 Swiftmailer/Twig”部分关注 instructions

这是我的代码:

require_once('/var/www/folder/includes/vendor/autoload.php');

$loader = new Twig_Loader_Filesystem(array('/var/www/templates/utilities/test'));
$twig = new Twig_Environment($loader, array(
    'cache' => '/var/www/templates/cached',
    'auto_reload' => true, // set to false to improve performance (Note: You have to clear the cache manually whenever a template is changed)
    'debug' => true,
    'use_strict_variables' => false,
));
$twig->addExtension(new Twig_Extension_Debug());



$swiftMailerTemplateHelper = new \WMC\SwiftmailerTwigBundle\TwigSwiftHelper($twig, '/var/www/templates/utilities/test');
// I'm not exactly sure what the value for the second parameter is supposed to be.
//The instructions referenced just list a variable called $web_directory.
//I'm assuming they just mean a path to where the templates are stored.

echo "hello world";

这是我得到的错误:

PHP 致命错误:类 'WMC\SwiftmailerTwigBundle\TwigSwiftHelper' 未在 /var/www/apps_mymea/utilities/test/email.php 第 16 行

【问题讨论】:

    标签: php twig swiftmailer


    【解决方案1】:

    参考文档中的命名空间不正确。

    正确的语法是:

    $swiftMailerTemplateHelper = new \WMC\SwiftmailerTwigBundle\Mailer\TwigSwiftHelper($twig, '/var/www/templates/utilities/test');
    //It was missing the \Mailer\ in the class path.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多