我想创建一个包含从数据库中获取的数据的动态页脚。 如何扩展TCPDF类以将这些数据放入?
// my DB stuff here
$datafromdb = getDataFromDB();
class MYPDF extends TCPDF {
// Page footer
public function Footer() {
// Position at 10 mm from bottom
$this->SetY(-10);
// Set font
$this->SetFont('dejavusans', 'I', 8);
$foot = $datafromdb.'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages();
$this->MultiCell(0, 10, $foot, 0, 'C');
}
}
答案 0 :(得分:1)
您可以添加__construct方法来传递数据 试试这个:
// my DB stuff here
$datafromdb = getDataFromDB();
class MYPDF extends TCPDF {
private $datafromdb ;//<-- to save your data
function __construct( $datafromdb , $orientation, $unit, $format )
{
parent::__construct( $orientation, $unit, $format, true, 'UTF-8', false );
$this->datafromdb = $datafromdb ;
//...
}
// Page footer
public function Footer() {
// Position at 10 mm from bottom
$this->SetY(-10);
// Set font
$this->SetFont('dejavusans', 'I', 8);
$foot = $this->datafromdb.'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages();
$this->MultiCell(0, 10, $foot, 0, 'C');
}
}