问题还在于:可以将功能从外部源添加到FPDF中吗????
我想从原始FPDF类中分离出一些“items”函数,并使用include或require将它们添加回该类。所有“包含”功能都是我项目的一种“模板”。我将拥有不同数量的项目/功能。拥有原始类中的所有函数会使代码很长。我想在自己的php文件中拥有每组“items”的函数,然后将它包含在类中......这可能吗?
这是我得到的错误:PHP致命错误:在/ home /....
中调用未定义的方法PDF_receipt :: Item1() <?php
date_default_timezone_set('America/Phoenix');
require('fpdf/fpdf.php'); // FPDF VERSION 1.81 12/20/2015
class PDF_receipt extends FPDF {
public function __construct ($orientation = 'L', $unit = 'pt', $format = 'Letter', $margin = 33) {
parent::__construct($orientation, $unit, $format, $margin);
$this->SetTopMargin($margin);
$this->SetLeftMargin($margin);
$this->SetRightMargin($margin);
$this->SetAutoPageBreak(true, $margin);
}
// HEADER FUNCTION
function Header() {
$this->SetFont('Arial', '', 16);
$this->SetXY(30, 15);
$this->SetFillColor(232, 249, 169);
$this->SetTextColor(100);
$this->Cell(0, 30, "APPAREL KITCHEN ONLINE ORDERING", 0, 1, 'C', true);
$this->Image("images/ttdinfocopy.jpg",40,55,225,60,"jpg", "");
$this->Image("images/mens-ladies-keiki.jpg",535,58,200,42,"jpg", "");
}
// ORDER SUBMIT DATE FUNCTION
function SubmitDate() {
$this->SetFont('Arial', '', 11);
$this->SetXY(150, 245);
$this->Cell(222, 10, 'Order Date: ' . date('F jS Y g:i:s A') . ' AZ time', 0, 1);
}
// HEADINGS TABLE CONSTRUCTION FUNCTION
function QtyTable() {
$this->SetFont('Arial', '', 9);
$this->SetTextColor(0);
$this->SetFillColor(240);
$this->SetLineWidth(1);
$this->SetXY(30, 233);
$this->Cell(100, 10, "", '0', 0, 'C', false);
$this->Cell(300, 10, "", '0', 0, 'C', false);
$this->Cell(95, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(28, 12, "3-6", 'LTR', 0, 'C', true);
$this->Cell(28, 12, "6-12", 'LTR', 0, 'C', true);
$this->Cell(28, 12, "12-18", 'LTR', 0, 'C', true);
$this->Cell(28, 12, "18-24", 'LTR', 0, 'C', true);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(38, 10, "", '0', 0, 'C', false);
$this->Ln(10);
$this->Cell(97, 10, "", '0', 0, 'C', false);
$this->Cell(300, 10, "", '0', 0, 'C', false);
$this->Cell(95, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "Month", 'LR', 0, 'C', true);
$this->Cell(28, 10, "Month", 'LR', 0, 'C', true);
$this->Cell(28, 10, "Month", 'LR', 0, 'C', true);
$this->Cell(28, 10, "Month", 'LR', 0, 'C', true);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(28, 10, "", '0', 0, 'C', false);
$this->Cell(38, 10, "", '0', 0, 'C', false);
$this->Ln(10);
$this->Cell(97, 20, "", '0', 0, 'C', false);
$this->Cell(300, 20, "", '0', 0, 'C', false);
$this->Cell(95, 20, "", '0', 0, 'C', false);
$this->Cell(28, 20, "2", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "4", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "6", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "8", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "10", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "12", 'LTR', 0, 'C', true);
$this->Cell(28, 20, "O/S", 'LTR', 0, 'C', true);
$this->Cell(38, 20, "", '0', 0, 'C', false);
$this->Ln(18);
$this->Cell(97, 20, "Item Name", '1', 0, 'C', true);
$this->Cell(300, 20, "Description", '1', 0, 'C', true);
$this->Cell(95, 20, "Color", '1', 0, 'C', true);
$this->Cell(28, 20, "XS", '1', 0, 'C', true);
$this->Cell(28, 20, "SM", '1', 0, 'C', true);
$this->Cell(28, 20, "MD", '1', 0, 'C', true);
$this->Cell(28, 20, "LG", '1', 0, 'C', true);
$this->Cell(28, 20, "XL", '1', 0, 'C', true);
$this->Cell(28, 20, "XX", '1', 0, 'C', true);
$this->Cell(28, 20, "XXX", '1', 0, 'C', true);
$this->Cell(38, 20, "Total", '1', 1, 'C', true);
}
// PLACEHOLDER ROW SO ITEM ROWS HAVE A STARTING POINT AFTER FORM SUBMITTED
function submittedItemRowPositioner() {
$this->SetFont('Arial', '', 10);
$this->SetFillColor(242);
$this->SetLineWidth(0);
$this->SetXY(33, 271);
$this->Cell(97, 20, '', '1', 0, 'L');
$this->Cell(300, 20, '', '1', 0, 'L');
$this->Cell(95, 20, '', '1', 0, 'L');
$this->Cell(28, 20, '', '1', 0, 'C');
$this->Cell(28, 20, '', '1', 0, 'C');
$this->Cell(28, 20, '', '1', 0, 'C');
$this->Cell(28, 20, '', '1', 0, 'C');
$this->Cell(28, 20, '', '1', 0, 'C');
$this->Cell(28, 20, '', '1', 0, 'C');
$this->Cell(28, 20, '', '1', 0, 'C');
$this->Cell(38, 20, '', '1', 1, 'C');
}
function MessageBottom() {
$this->SetFont('Arial', '', 10);
$this->SetFillColor(242);
$this->SetXY(35, 560);
$message = "Thank you for your online order. If you have any questions, you can email us at the following address: ";
$this->Write(12, $message);
}
function EmailAddress() {
$this->SetFont('Arial', 'U', 10);
$this->SetTextColor(1, 162, 232);
$this->SetXY(488, 559.5);
$this->Write(12, "orders@xxxxxxx.com", "mailto:orders@xxxxxxxns.com?subject=New Order From Ka'anapali&body=Link to new PO: http://xxxxxxxxxxx/xxxxx/php-pdf-practice/receipts/".$_POST['ponum'].".pdf");
}
function Footer() {
$this->SetFont('Arial', '', 10);
$this->SetTextColor(0);
$this->SetXY(30, 575);
$this->Cell(0, 35, "Apparel Designs", 'T', 0, 'C');
}
********#I would like to put the functions below in their own file and "include" it here. There could be 40 - 60 item functions #********
// KA'ANAPALI ITEMS BELOW
// ITEM 1
function Item1() {
if (isset($_POST["item1Qty"][0]) && !empty($_POST["item1Qty"][0]) ||
isset($_POST["item1Qty"][1]) && !empty($_POST["item1Qty"][1]) ||
isset($_POST["item1Qty"][2]) && !empty($_POST["item1Qty"][2]) ||
isset($_POST["item1Qty"][3]) && !empty($_POST["item1Qty"][3]) ||
isset($_POST["item1Qty"][4]) && !empty($_POST["item1Qty"][4]) ||
isset($_POST["item1Qty"][5]) && !empty($_POST["item1Qty"][5])) {
$item1Qty = $_POST['item1Qty'];
$item = $_POST['item1'];
$desc = $_POST['desc1'];
$color = $_POST['color1'];
$this->SetFont('Arial', '', 10);
$this->SetFillColor(242);
$this->SetLineWidth(1);
$this->SetX(33);
$this->Cell(97, 20, $item, 'LRB', 0, 'L');
$this->Cell(300, 20, $desc, 'LRB', 0, 'L');
$this->Cell(95, 20, $color, 'LRB', 0, 'L');
$this->Cell(28, 20, $item1Qty[0], 'LRB', 0, 'C');
$this->Cell(28, 20, $item1Qty[1], 'LRB', 0, 'C');
$this->Cell(28, 20, $item1Qty[2], 'LRB', 0, 'C');
$this->Cell(28, 20, $item1Qty[3], 'LRB', 0, 'C');
$this->Cell(28, 20, $item1Qty[4], 'LRB', 0, 'C');
$this->Cell(28, 20, $item1Qty[5], 'LRB', 0, 'C');
$this->Cell(28, 20, '', 'LRB', 0, 'C');
$this->Cell(38, 20, array_sum($item1Qty), 'LRB', 1, 'C');
}
}
// ITEM 2
function Item2() {
if (isset($_POST["item2Qty"][0]) && !empty($_POST["item2Qty"][0]) ||
isset($_POST["item2Qty"][1]) && !empty($_POST["item2Qty"][1]) ||
isset($_POST["item2Qty"][2]) && !empty($_POST["item2Qty"][2]) ||
isset($_POST["item2Qty"][3]) && !empty($_POST["item2Qty"][3]) ||
isset($_POST["item2Qty"][4]) && !empty($_POST["item2Qty"][4]) ||
isset($_POST["item2Qty"][5]) && !empty($_POST["item2Qty"][5])) {
$item2Qty = $_POST['item2Qty'];
$item = $_POST['item2'];
$desc = $_POST['desc2'];
$color = $_POST['color2'];
$this->SetFont('Arial', '');
$this->SetFillColor(242);
$this->SetLineWidth(1);
$this->SetX(33);
$this->Cell(97, 20, $item, 'LRB', 0, 'L');
$this->Cell(300, 20, $desc, 'LRB', 0, 'L');
$this->Cell(95, 20, $color, 'LRB', 0, 'L');
$this->Cell(28, 20, $item2Qty[0], 'LRB', 0, 'C');
$this->Cell(28, 20, $item2Qty[1], 'LRB', 0, 'C');
$this->Cell(28, 20, $item2Qty[2], 'LRB', 0, 'C');
$this->Cell(28, 20, $item2Qty[3], 'LRB', 0, 'C');
$this->Cell(28, 20, $item2Qty[4], 'LRB', 0, 'C');
$this->Cell(28, 20, $item2Qty[5], 'LRB', 0, 'C');
$this->Cell(28, 20, '', 'LRB', 0, 'C');
$this->Cell(38, 20, array_sum($item2Qty), 'LRB', 1, 'C');
}
}
// ITEM 3, ITEM 4, etc........
答案 0 :(得分:0)
您可以创建具有此附加信息的帮助程序类:
class PDFHelper {
public static function addCell($instance, ...) {
}
public static function setHeader($instance, ...) {
}
}
然后在主要班级:
class PDFReceipt extends FPDF {
PDFHelper::addCell($this, 95, 20, "Color");
/* ... */
}