我正在生成pdf报告并将其添加为电子邮件的附件。我正在使用tcpdf扩展并使用Yii框架。我怀疑是在哪里放置代码来生成pdf。我可以在发送电子邮件之前将其添加到控制器代码中,但我想创建一个单独的函数,在调用时生成pdf并将其保存到磁盘。分离Yii中的pdf生成模块
这里是我的示例代码
$transaction->commit();
$mail = Yii::app()->Smtpmail;
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->SetFrom("[email protected]", 'XXX Admin');
//$headers = "Content-Type: text/html; charset=UTF-8";
$mail->Subject = "Confirmation of survey completion";
$mail->MsgHTML("Hi $survey->first_name $survey->last_name, <br><br>Thank you for completing the survey. The details of your survey result will be sent to the leader. <br><br>Please contact the leader for further details.<br><br>Regards,<br>Admin, XXX");
$mail->AddAddress("[email protected]", "");
$mail->CharSet = 'UTF-8';
//to invoke another controller/component to generate pdf here
$controller1 = new PdfReportController("test");
$controller1->actionEnglishReport();
$dir = realpath(__DIR__ . '/../runtime/pdf-assets');
$file = $dir . '/export.pdf';
$mail->AddAttachment($file);
if(!$mail->Send())
{
Yii::log("Mailer Error: " . $mail->ErrorInfo, 'error','application');
}
else
{
Yii::log('Data1 saved!. Mail sent', 'info','application');
}
我不是如何将这个PDF生成模块分开很清楚。请帮助
更新: 我设法向PDF模块这样的分离:
//Pdfreports is a component class which has MandarinReport as a static method
PdfReports::MandarinReport();
$dir = realpath(__DIR__ . '/../runtime/pdf-assets');
$file = $dir . '/export.pdf';
$mail->AddAttachment($file);
的问题是,虽然创建PDF,带有附件的邮件没有发送