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

发布于 2024-09-27 09:34:54 字数 864 浏览 0 评论 0原文

我有一个用于打印 pdf 的 php 文件(使用 FPDF)。在此文件中,我有一个变量 $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 变量?

I have a php file that I use to print pdf (using FPDF). In this file I have a variable $date and I would like to show this variable $date in the header on each of the pages of my pdf document.
That is my variable $date:

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

And this is the class 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();
    } ...

The problem is that the second $this->Write prints nothing.

I checked that if I call $this->setDate('abcd');, it prints "abcd" ok.

How can I pass this $date variable in my pdf header function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女中豪杰 2024-10-04 09:34:54

我不确定,因为我已经大约五年没有使用它们了,但是您是否必须在 Header() 函数内将 $date 声明为全局变量?

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

I'm not sure because I've not used them in about five years, but don't you have to declare $date as being a global inside the Header() function?

function Header() {
    $date = $GLOBALS['date'];
    ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文