2011-12-01 137 views
0

如何在类之外设置函数或者有更好的方法来实现它?类和扩展

我需要写在每个页面的顶部东西..因为写入的数据具有可变的高度,我不能用Header()

require_once 'tcpdf/tcpdf.php'; 

class TCPDF_ext extends TCPDF { 
    public function AcceptPageBreak(){ 
     $this->AddPage(); 
     $this->lastpage(); 
     $this->add_top(); 

     return false; 
    } 
} 

$pdf = new TCPDF_ext(); 

$pdf->add_top = function(){ 
    // write something on the top of each page 
}; 

回答

0

我不太知道你正在尝试这样做,但这不行吗?

require_once 'tcpdf/tcpdf.php'; 

class TCPDF_ext extends TCPDF { 
    public function AcceptPageBreak(){ 
     $this->AddPage(); 
     $this->lastpage(); 
     $this->add_top(); 

     return false; 
    } 
    protected function add_top(){ 
     //write stuff to page top 
    } 
} 

$pdf = new TCPDF_ext(); 
$pdf->AcceptPageBreak()