gpt4 book ai didi

php - 如何分配 mySQL 值 -> HTML -> PDF (MPDF)

转载 作者:行者123 更新时间:2023-11-29 20:37:22 25 4
gpt4 key购买 nike

以下是我的代码:

PHP 函数

public function createReport()
{
$data = [];
//load the view and saved it into $html variable
$html=$this->load->view('forms/reports', $data, true);

//this the the PDF filename that user will get to download
$pdfFilePath = "Report.pdf";

//load mPDF library
$this->load->library('m_pdf');

//generate the PDF from the given html
$this->m_pdf->pdf->WriteHTML($html);

//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "D");
}
<小时/>

查看 HTML 代码:表单/报告

<body>
<table>
<tr>
<td colspan="3" style="text-align:center;"><label id="lblTitle"> Testing 1<label> </td>
<td style="width:20%;" valign="top" align="right" style="text-align:center;padding:3mm;">
<label>App :101</label><br><label>REV : 5</label>
</td>
</tr>
<tr>
<td colspan="4" style="text-align:left; padding-left:10px;">
<b>CUSTOMER</b> : <label id="lblDesc1"> Bafna automobiles</label><br />
<b>NUMBER</b> : <label id="lblDesc2"> 100100101122</label><br />
<b>DESCRIPTION</b> : <label id="lblDesc3">Single bus </label><br />
<b>No</b> : <label id="lblDesc4">Auto 1 to auto 10</label><br />
</td>

</tr>
</table>
</body>
<小时/>

从数据库加载数据

 public function loadJobPanels($TestId)
{
$this->db->select("*");
$this->db->from("auto_job");

$this->db->where("AutoTestId = ",$TestId);

$query = $this->db->get();
$data['get_Data'] = $query->result();
}
<小时/>

如何将“$data['get_Data']”分配给我的 View 并将其发送到$html以进一步传递到$this->m_pdf->pdf->WriteHTML($html);我能够在 HTML 页面( View )中显示数据,但不知道如何将带有数据的 HTML 传递到 PDF。请帮忙。

最佳答案

假设两个函数都在同一个类中。您可以将数据作为类的属性(变量)传递。

Class someClass
{
private $data = [];

public function createReport(){
$data = $this->data;
...
}
public function loadJobPanels($TestId){
...
$this->data = $data;
}
}

但是,您应该检查类变量是否已设置。

关于php - 如何分配 mySQL 值 -> HTML -> PDF (MPDF),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38736406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com