2017-06-21 62 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

存在同样的问题 –

相关问题