我在生成PDF的项目上使用CodeIgniter。它在单个PDF中工作一次,但现在我尝试了另一个错误。这是代码:
class Checkout extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('PurchaserModel', 'purchaser');
....
$this->load->library('M_pdf');
}
public function save(){
.....
$data['orders'] = $this->order->get_order_details($logged_in_id);
if($data['orders']){
$details = $this->purchaser->get_purchaser_details($this->session->userdata['logged_in']['username']);
$data['details'] = convertvalue($details);
$order_id = $data['orders'][0]['order_id'];
$data['order_id'] = $order_id;
}
// 1st PDF work fine if the other generate PDF is commented out
$purchaser_sheet_html = $this->load->view('pdf/purchaser_sheet', $data, true);
$purchaser_sheet_html2 = $this->load->view('pdf/purchaser_sheet_page_2', $data, true);
$pdf1 = $this->m_pdf->load();
$pdfFilePath1 = uniqid(rand(), true);
$pdfFilePath = "purchase-order-summary-".date('Ymdhis')."-".$pdfFilePath1.".pdf";
$pdf1->WriteHTML($purchaser_sheet_html);
$pdf1->AddPage();
$pdf1->WriteHTML($purchaser_sheet_html2);
$pdf1->Output("./uploads/".$pdfFilePath, "F"); // this is line 425 and got error
// 2nd PDF when this code is up, it got an error
$construction_sheet_summary = $this->load->view('pdf/construction_sheet_summary', $data, true);
$pdf2 = $this->m_pdf->load();
$pdfFilePath2 = uniqid(rand(), true);
$pdfFilePath_2 = "construction-sheet-summary-".date('Ymdhis')."-".$pdfFilePath2.".pdf";
$pdf2->WriteHTML($construction_sheet_summary); // this is line 433 and got error
$pdf2->Output("./uploads/".$pdfFilePath_2, "F");
$this->db->update($this->db->dbprefix('order'), array('purchaser_sheet' => $pdfFilePath, 'construction_sheet' => $pdfFilePath_2), array('ID' => $insert_id));
$email_settings = $this->settings->email_settings();
}
这是完整的错误消息:
A PHP Error was encountered
Severity: Warning
Message: count(): Parameter must be an array or an object that implements Countable
Filename: mpdf/mpdf.php
Line Number: 1770
Backtrace:
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 1770
Function: _error_handler
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 7591
Function: Close
File: C:\xampp1\htdocs\dev.app.com\public\application\controllers\Checkout.php
Line: 425
Function: Output
File: C:\xampp1\htdocs\dev.app.com\public\index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: The each() function is deprecated. This message will be suppressed on further calls
Filename: mpdf/mpdf.php
Line Number: 9143
Backtrace:
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 9143
Function: each
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 27927
Function: _putimages
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 9508
Function: _putresources
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 1797
Function: _enddoc
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 7591
Function: Close
File: C:\xampp1\htdocs\dev.app.com\public\application\controllers\Checkout.php
Line: 425
Function: Output
File: C:\xampp1\htdocs\dev.app.com\public\index.php
Line: 315
Function: require_once
An uncaught Exception was encountered
Type: Error
Message: Class 'MpdfException' not found
Filename: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line Number: 32456
Backtrace:
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 22328
Function: ConvertSize
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 15440
Function: setCSS
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 13614
Function: OpenTag
File: C:\xampp1\htdocs\dev.app.com\public\application\controllers\Checkout.php
Line: 433
Function: WriteHTML
File: C:\xampp1\htdocs\dev.app.com\public\index.php
Line: 315
Function: require_once
我尝试调试代码,发现这一行出现了isseu
$construction_sheet_summary = $this->load->view('pdf/construction_sheet_summary', $data, true);
我construction_sheet_summary.php
存在,我试图删除该文件上的所有php
代码,但遇到相同的错误。
有人知道我的案子吗?
答案 0 :(得分:0)
按照@Viney在评论中的建议,使用composer升级到(最好是)mPDF的最新版本-这将解决依赖关系和each()
弃用警告。