如何将值从foreach传递到codeigniter中的视图

时间:2018-03-15 04:32:03

标签: php mysql codeigniter codeigniter-3

如何在控制器中循环值,将其发送到CodeIgniter中查看

我尝试使用以下代码

控制器

 public function getdata()
 {
    $data =  $this->Mdi_download_invoices->download_pdf_files(12);       
    foreach ($data as $d)   
        {
             $mpdf = new \Mpdf\Mpdf();
             $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>

但数据不在视图中打印。如何打印值?

2 个答案:

答案 0 :(得分:2)

您无法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;检查您的result objectrowresult

答案 1 :(得分:1)

我认为你正在寻找这个:

<?php 
     public function getdata()
     {
        $data =  $this->Mdi_download_invoices->download_pdf_files(12);       
        foreach ($data as $d)   
            {
                $mpdf = new \Mpdf\Mpdf();
                $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);
            }
     }

?>