FPDF 标头中带有 php 变量的问题
我有一个用于打印 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定,因为我已经大约五年没有使用它们了,但是您是否必须在
Header()
函数内将 $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?