如何在控制器中循环值,将其发送到CodeIgniter中查看
我尝试过以下代码
控制器
public function getdata()
{
$data = $this->Mdi_download_invoices->download_pdf_files(12);
foreach ($data as $d)
{
$mpdf = new MpdfMpdf();
$html = $this->load->view('download_all_invoices/pdf',$d,true);
$mpdf->WriteHTML($html);
$mpdf->Output($estructure.$d->invoice_id,'F');
}
}
视图
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
echo $d->invoice_id;
?>
</body>
</html>
但数据不会在视图中打印。如何打印值?
无法foreach
并传递要查看的数据。
public function getdata()
{
$result = $this->Mdi_download_invoices->download_pdf_files(12);
$data['d'] = $result;
$this->load->view('download_all_invoices/pdf',$data);
}
注意:由于您正在使用
echo $d->invoice_id;
请检查结果对象(row
,result
(
我想你正在寻找这个:
<?php
public function getdata()
{
$data = $this->Mdi_download_invoices->download_pdf_files(12);
foreach ($data as $d)
{
$mpdf = new MpdfMpdf();
$html = $this->load->view('download_all_invoices/pdf',$d,true);
$mpdf->WriteHTML($html);
$mpdf->Output($estructure.$d->invoice_id,'F');
$this->load->view('download_all_invoices/pdf',$d);
}
}
?>