【发布时间】:2014-12-25 10:20:06
【问题描述】:
我正在使用 TCPDF 制作奖励生成器。 它检查奖励的类型,并根据它填充 image_path 变量(以及一些与此问题无关的其他变量。
switch($award){
case 25:
$img_file = '../../img/award_25.png';
break;
case 50:
$img_file = '../../img/award_50.png';
break;
... and so on ...
}
更进一步,如 TCPDF 的 example_051 所示,它们扩展了类以定义背景图像。 该图像的路径是上面创建的变量 $img_file 中的路径。
require_once('tcpdf_include.php');
class MYPDF extends TCPDF {
public function Header() {
// get the current page break margin
$bMargin = $this->getBreakMargin();
// get current auto-page-break mode
$auto_page_break = $this->AutoPageBreak;
// disable auto-page-break
$this->SetAutoPageBreak(false, 0);
// margins Left, Top, Right, Bottom in pixels
$this->Image($img_file, -9, -8, 316, 225, '', '', '', false, 300, '', false, false, 0);
// restore auto-page-break status
$this->SetAutoPageBreak($auto_page_break, $bMargin);
// set the starting point for the page content
$this->setPageMark();
}
}
由于范围的原因,变量 $image_file 在扩展中是未知的。有什么方法可以让我完成这项工作吗?
提前致谢!
【问题讨论】:
标签: php class variables tcpdf extend