请你帮我解释一下这段代码......
<?php
require('fpdf/fpdf.php');
class PDF_reciept extends FPDF
{
function __construct($orientation = 'P', $unit = 'pt', $format = 'Letter', $margin = 40)
{
$this->FPDF($orientation, $unit, $format);
$this->SetTopMargin($margin);
$this->SetLeftMargin($margin);
$this->SetRightMargin($margin);
$this->SetAutoPageBreak(true, $margin);
}
function Header()
{
$this->SetFont('Arial', 'B', 20);
$this->SetFillColor(36, 96, 84);
$this->SetTextColor(225);
$this->Cell(0, 30, "Nettuts+ Online Store", 0, 1, 'C', true);
}
function Footer()
{
$this->SetFont('Arial', '', 12);
$this->SetTextColor(0);
$this->XY(40, -60);
$this->Cell(0, 20, "Thank you for shopping at Nettuts+", 'T', 0, 'C');
}
}
$pdf = new PDF_reciept();
$pdf->Output();
?>
答案 0 :(得分:0)
错误Fatal error: Call to undefined method PDF_reciept::FPDF() in C:\wamp\www\pdf\cr.php on line 8
说你试图访问PDF_reciept::FPDF()
方法,但是你的课程中没有这样的方法。
答案 1 :(得分:0)
您正在覆盖构造函数,因此您必须在构造函数之上调用具有预期签名的父构造函数,例如parent::__construct();
:
public function __construct($orientation = 'P', $unit = 'pt', $format = 'Letter', $margin = 40)
{
parent::__construct($orientation, $unit, $format, $margin);
//$this->FPDF($orientation, $unit, $format);
$this->SetTopMargin($margin);
$this->SetLeftMargin($margin);
$this->SetRightMargin($margin);
$this->SetAutoPageBreak(true, $margin);
}
此类中的所有函数都应使用访问修饰符(public,private etc。)
声明答案 2 :(得分:0)
请检查您是否有$ this-&gt; FPDF($ orientation,$ unit,$ format); fpdf / fpdf.php中定义的函数。
或者如果你想调用父FPDF构造函数,那么使用parent :: __ construct($ orientation,$ unit,$ format,$ margin);