0
我正在嘗試編寫一個可以調用多個類的函數,每個函數都會將一個小部件添加到單個PDF文件,然後返回整個PDF文件。在多個類中使用TCPDF
這裏的構造函數的代碼:
<?php
class PdfConstructor {
protected $logger; // I'm sure there's another way to use the logger located in the public dependencies without having to initalise it here
public function __construct($logger){
$this->logger = $logger;
}
public function studentPdf(){
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// ---------------------------------------------------------
require 'pdfwidgets/studentheader.php'; // TODO: Need to load this via autoloader
$headerController = new StudentHeader($pdf);
$headerInfo = $hederController->getHeader();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('C:\xampp7\htdocs\edquire-api\logs\test.pdf', 'F');
}
}
在
studentheader
然後,我有這樣的:
<?php
class StudentHeader {
protected $pdf;
public function __construct($pdf){
$this->$pdf = $pdf;
}
public function getHeader(){
$this->pdf->AddPage();
}
}
我想給$pdf
對象傳遞給studentheader
但我得到的錯誤:
Catchable fatal error: Object of class TCPDF could not be converted to string in C:\xampp7\htdocs\edquire-api\classes\pdfwidgets\studentheader.php on line 8
它爲什麼試圖將其轉換爲字符串,並有沒有更好的方法來實現使用小部件構建PDF?
投票關閉,因爲你只是要求我們找到你的錯字。 –