【问题标题】:Use an Email Template from a CakePHP Plugin使用 CakePHP 插件中的电子邮件模板
【发布时间】:2011-05-16 16:06:57
【问题描述】:

我有一个正在发送电子邮件的 CakePHP Shell 脚本。该脚本包含在 CakePHP 插件 (foo) 中。

将电子邮件模板设置为

$this->Email->template = "foo/email_template_name";

不起作用,电子邮件发送成功,但是电子邮件只是说

Not Found: /path_to_app/app/views/elements/email/html/foo/email_template_name.ctp

我已验证模板名称正确且确实存在。

小笔记:

$this->Email->sendAs = "both";

如果模板移动到/path_to_app/app/views/elements/email/html/foo/email_template_name.ctp 它确实工作正常。但是,我希望尽可能多地将其作为自包含的电子邮件发送,包括插件本身中的模板。

【问题讨论】:

    标签: email cakephp plugins


    【解决方案1】:

    您需要告诉 CakeEmail 插件的名称。 (蛋糕 2.0.x)

    在你的模型中

    $email = new CakeEmail();
    $email->template('Foo.email_template_name');
    

    或控制器

    $this->email->template('Foo.email_template_name');
    

    您需要为电子邮件创建视图:

    Plugin/Foo/View/Emails/html/email_template_name.ctp
    Plugin/Foo/View/Emails/text/email_template_name.ctp
    

    【讨论】:

    • 这对我有用。蛋糕告诉我我的文件丢失了,但实际上它没有。解决方案是在我的模板名称前加上插件名称。
    【解决方案2】:

    请为 $this->Email 发布您的所有代码。

    检查:

    $this->Email->sendAs = 'html';
    

    你试过了吗

    $this->Email->template = "email_template_name";
    

    并将模板移动到

    /path_to_app/app/views/elements/email/html/email_template_name.ctp
    

    【讨论】:

    • 感谢迈克的回复,是的,所有这些都已通过验证。
    【解决方案3】:

    再次检查您的路径!

    我遇到了同样的问题,我意识到我将模板放置在: /path_to_app/app/plugins/my_plugin_name/views/elements/email/my_template.ctp

    但正确的路径是: /path_to_app/app/plugins/my_plugin_name/views/elements/email/html/my_template.ctp

    因为我在控制器上使用“html”值作为“sendAs”

    $this->Email->sendAs = 'html';

    【讨论】:

    • 你使用的是哪个版本的 cakephp?
    • 我猜它是在 1.3.8 上。你在处理什么麻烦?我现在在 2.0 工作,但还没有开始发送电子邮件:)
    • 这适用于 cakephp 1.3.11 中 colares 建议的路径
    【解决方案4】:

    只是这个功能在 cakephp 1.3 中没有实现。 您将在新鲜的 cakephp 2.0.0 版本中获得它 http://bakery.cakephp.org/articles/lorenzo/2011/10/16/cakephp_2_0_released

    由于该错误已得到修复: http://cakephp.lighthouseapp.com/projects/42648/tickets/1743-cakeemail-in-plugins-doesnt-work-well-with-views

    您最终可能会在 1.3 中要求或提供反向移植。我不知道 cakephp 后缀策略和津贴。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-18
      • 2017-11-15
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多