我正在尝试构建OOP PHP发票脚本。我想将数据输出到PDF,所以我正在使用FPDF。我在这样的发票类的方法中创建该对象:
public function renderPDF() {
require("pdf.class.php");
$this->invoicePDF = new PDF();
$this->invoicePDF->AddPage();
$this->invoicePDF->setfont('Helvetica','',12);
//build PDF
}
在pdf.class.php中使用静态数据进行测试时,此方法及其调用可以完美地工作。但是,如何在pdf类中使用$ this(发票类)的数据呢?
我尝试在创建new PDF($this)
时传递$ this并在__construct中调用它。是这样吗它引发了FDPF错误/警告:警告:count():参数必须是实现Countable的数组或对象
为全面披露,请参阅pdf.class.php(两行之间有荷兰语注释):
require('fpdf181/fpdf.php');
include("fpdf181/font/helvetica.php");
include("fpdf181/font/helveticab.php");
include("fpdf181/font/helveticabi.php");
include("fpdf181/font/helveticai.php");
class PDF extends FPDF
{
private $invoiceData;
function __construct($invoiceclass) {
$this->invoiceData = $invoiceclass;
}
//Page header
function Header()
{
//Logo
$this->Image('../img/icon-192-circle.png',10,8,33);
//Arial vet 15
$this->setfont('Helvetica','B',15);
//Beweeg naar rechts
$this->Cell(80);
//Titel
$this->Cell(30,'Factuur','C');
$this->Cell(30,$this->invoiceData->getInvoiceDate(),'C');
//Line break
$this->Ln(20);
}
//Page footer
function Footer()
{
//Positie 1.5 cm van de onderkant
$this->SetY(-15);
//Arial cursief 8
$this->setfont('Arial','I',8);
//Pagina nummer
$this->Cell(0,'Gelieve binnen 14 dagen overmaken op IBAN: INGB 12345678910 onder vermelding van factuurnummer.','C');
}
}
我已经在Stackoverflow上搜索了答案,阅读了FPDF的文档,但是没有找到适合我的答案。 希望有人可以帮助或指出正确的方向!