带有php变量的FPDF头中的问题

时间:2010-10-13 08:04:42

标签: php fpdf

我有一个用于打印pdf(使用FPDF)的php文件。在这个文件中我有一个变量$ date,我想在我的pdf文档的每个页面的标题中显示这个变量$ date。 那是我的变量$ date:

$convert_date=strtotime($selected_date);
global $date;
$date=date("d/m/Y",$convert_date);

这是FPDF类:

class PDF extends FPDF{

    function setDate($dat){
        $this->header_date = $dat;
    }

    function getDate(){
        return $this->header_date;
    }

    function Header(){
        $this->SetFont('Arial','B',16);
        $this->setDate($date);
        $this->Write (10, '       Date: '); //1° Write
        $this->Write (10, $this->getDate()); //2° Write NOT WORKING 
        $this->Ln();
    } ...

问题是第二个$ this-> Write什么都不打印。

我检查过如果我打电话给 $ this-> setDate('abcd'); ,它会打印“abcd”确定。

如何在我的pdf标题函数中传递此$ date变量?

1 个答案:

答案 0 :(得分:5)

我不确定,因为我在大约五年内没有使用它们,但是你不必声明$ date是Header()函数中的全局吗?

function Header() {
    $date = $GLOBALS['date'];
    ...