我正在生成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,帶有附件的郵件沒有發送