致命错误:在第8行的C:\wamp\www\PDF\cr.php中调用未定义的方法PDF_receipt::FPDF()
你能帮我翻译一下这个代码吗致命错误:在第8行的C:\wamp\www\PDF\cr.php中调用未定义的方法PDF_receipt::FPDF(),php,fpdf,Php,Fpdf,你能帮我翻译一下这个代码吗 <?php require('fpdf/fpdf.php'); class PDF_reciept extends FPDF { function __construct($orientation = 'P', $unit = 'pt', $format = 'Letter', $margin = 40) { $this->FPDF($orientation, $unit,
<?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();
?>
错误
致命错误:调用第8行C:\wamp\www\PDF\cr.php中未定义的方法PDF_receipt::FPDF()
表示您试图访问PDF_receipt::FPDF()
方法,但您的类中没有此类方法。您正在重写构造函数,因此必须调用具有预期签名的父构造函数,如父::\u 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等)声明。请检查您是否有$this->FPDF($orientation,$unit,$format);在fpdf/fpdf.php中定义的函数
或者,如果要调用父FPDF构造函数,则使用父::u构造函数($orientation,$unit,$format,$margin) 第8行有一个问题。太好了,标记答案以结束主题。