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」。 注:沒有使用變量$用戶的,它是用來在我的實際代碼
什麼你的代碼錯了,你的鬥爭在哪裏?你可以用和你的文章相同的方式發送多維數組 – JYoThI
var_dump($ data);''的輸出是什麼?用這個信息擴展你的問題。 – Tpojka
你想要什麼。 ?你可否請探索。 –