CodeIgniter:调用非对象上的成员函数WriteHTML() [英] CodeIgniter: Call to a member function WriteHTML() on a non-object
问题描述
使用MPDF下载pdf文件时出现此错误。我在下面加载代码:
$ html = $ this-> load-> view('customer / case_report ',$ this-> data,true);
$ pdfFilePath = output_pdf_name.pdf;
$ this-> load-> library(’M_pdf’);
$ this-> M_pdf-> pdf-> WriteHTML($ html);
$ this-> M_pdf-> pdf-> Output('CaseReport_CaseNo _'。$ caseNo。'。pdf','D');
更新
此处附有屏幕截图:
< a href = https://i.stack.imgur.com/GTZKx.png rel = nofollow noreferrer>
任何帮助将不胜感激。谢谢
好的,我已经模拟了这种情况,有效的方法如下
从
但是随后我将输出中的F开关替换为D进行下载
公共函数mdfTest()
{
$ pdfFilePath = time()。 _ order.pdf;
$ this-> load-> library(’M_pdf’);
$ html =< html>< h1>这是测试pdf< / h1>< / html>;
$ this-> m_pdf-> pdf-> WriteHTML($ html);
//下载。
$ this-> m_pdf-> pdf-> Output($ pdfFilePath, D);
}
而且有效。创建了一个PDF文件,例如
I am getting this error when I an downloading a pdf file using MPDF. I am loading the code here below:
$html = $this->load->view('customer/case_report',$this->data, true);
$pdfFilePath = "output_pdf_name.pdf";
$this->load->library('M_pdf');
$this->M_pdf->pdf->WriteHTML($html);
$this->M_pdf->pdf->Output('CaseReport_CaseNo_'.$caseNo.'.pdf', 'D');
UPDATE Attaching screenshot here:
Any help will be greatly appreciated. Thank you
Alright I have Simulated the case and what Worked is as follows
Downloaded Library from mPDF Library using Codeigniter
Placed it in application/third_party. Created a File M_pdf.php in application/libraries
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once APPPATH.'/third_party/mpdf/mpdf.php';
class M_pdf {
public $param;
public $pdf;
public function __construct($param = "'c', 'A4-L'")
{
$this->param =$param;
$this->pdf = new mPDF($this->param);
}
}
?>
Created a Test function in My Controller to test. At first I was trying to save it and getting an error like
But then I replace the F switch in Output with D for download
public function mdfTest()
{
$pdfFilePath = time()."_order.pdf";
$this->load->library('M_pdf');
$html="<html><h1>This is test pdf</h1></html>";
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "D");
}
And it worked. Created a PDF file like
这篇关于CodeIgniter:调用非对象上的成员函数WriteHTML()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!