电子邮件模板未使用主题版本 [英] Email template not using themed version

查看:75
本文介绍了电子邮件模板未使用主题版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CakePHP 1.3和文档。我的模板的html版本位于app / views / elements / email / html / reservation.ctp中,并且按预期工作。

I am using CakePHP 1.3 and the built in email features as described in the documentation. I have the html version of the template located in app/views/elements/email/html/reservation.ctp and its working as expected.

$this->Email->template = 'reservation'; // no '.ctp'

我也有一个主题设置,大多数主题文件都正确覆盖默认文件。我的问题是从主题站点调用主题电子邮件模板时未使用主题模板,它仍在默认路径中使用电子邮件模板文件。

I also have a theme setup and most of the themed files are correctly overriding the default files. My problem is the themed email template is not being used when called from the themed site, its still using the email template file in the default path.

默认值为: app / views / elements / email / html / reservation.ctp

The default is at: app/views/elements/email/html/reservation.ctp

主题位于:app / views / themed / myTheme / elements / email / html / reservation.ctp

The theme is at: app/views/themed/myTheme/elements/email/html/reservation.ctp

电子邮件模板分配是否可以自动处理主题,而无需对路径进行硬编码,还是有其他解决方案?其他人有这个问题吗?

Should the email template assignment automatically work with themes without the need for hard coding a path or is there another solution? Anyone else have this issue?

推荐答案

在cakephp中,当您要创建电子邮件模板时。假设我们要创建一个HTML电子邮件。

in cakephp when you want to create email template. Lets suppose we want to create an Html email. and email config is configured.

查看[文件结构]:

1)您的内容电子邮件应带有变量位于View / Emails / html [reservation.ctp]

2)您的模板应位于View / Layouts / Emails / html [default.ctp或您创建的任何新模板中]

1) your content email with variables should be located in View/Emails/html [reservation.ctp]
2) your template should be located in View/Layouts/Emails/html [default.ctp OR any new template you have made]

控制器:

注意:某些人会在您编写动作(在控制器中),您必须为其编写视图。在这种情况下(用于发送电子邮件)是完全错误的。

Note: some people think when you write an action(in controller) you have to write a view for it. In this case (for sending email) is completely wrong. only if you want to show the result which email sent successfully or not then is fine.

可以说ReserveController;)和sendReservationEmail

lets say ReserveController ;) and sendReservationEmail

function sendReservationEmail( $to, $from,$subject ,$template, $variables=array()){

        $Email = new CakeEmail();
        $Email->config('smtp')
            ->viewVars($variables) 
            ->emailFormat('html')
            ->template($template['page'], $template['layout'])  //'reservation', 'default'
            ->from($from)                                      //'me@example.com' => 'My Site'    
            ->to($to)                                          //'you@example.com'
            ->subject($subject) //'Resevation'
            ->send();       
    }

视图(View / Emails / html / reservation.ctp):

Views (View/Emails/html/reservation.ctp):

Dear $this->viewVars['name'];

Welcome to our restaurant .....

这篇关于电子邮件模板未使用主题版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆