2017-06-21 60 views
0

使用mPDF庫創建PDF。該文件已創建,我嘗試創建不同的PDF文件,但創建了我需要的文件數量,但所有文件都包含第一個文件的相同數據。這是我的問題的示例代碼如何將函數fgetcsv()中的值傳遞給codeigniter中的視圖?

控制器

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Home extends CI_Controller{ 

    public function page1(){ 
      $this->load->view('view_upload'); 

    } 

     public function page2(){ 
     $file = fopen($_FILES['file']['tmp_name'], 'r+');   
     $i=0; 

      $user['data']=fgetcsv($file); 
      echo "<br><br>"; 
      //print_r($user); 

      //load the view and saved it into $html variable 
      $html=$this->load->view('print_1', $user, true); 

      //this the the PDF filename that user will get to download 
      $pdfFilePath = $i.".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("output/".$pdfFilePath, 'F'); 



      ++$i; 
      $html=$this->load->view('print', $user, true); 

      //this the the PDF filename that user will get to download 
      $pdfFilePath = $i.".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("output/".$pdfFilePath, 'F'); 

     fclose($file); 

} 
} 

看法是:

print_1

<?php 
echo "print_1"; 
?> 

打印

<?php 
echo "print"; 
?> 

它創建兩個PDF文件,都有數據「print_1」。 注:沒有使用變量$用戶的,它是用來在我的實際代碼

+0

什麼你的代碼錯了,你的鬥爭在哪裏?你可以用和你的文章相同的方式發送多維數組 – JYoThI

+0

var_dump($ data);''的輸出是什麼?用這個信息擴展你的問題。 – Tpojka

+0

你想要什麼。 ?你可否請探索。 –

回答

0

試試這個(是不是真的那麼明顯嗎?)

在print.php

foreach($data AS $key => $arrData) 
{ 
    echo implode(",",$arrData); 
    echo "<br />"; 
} 
+0

存在同樣的問題 –

相關問題