0

我正在尝试将数组中的名字和姓氏放入页脚,但出现未定义变量错误。这可以在 PDF 的正文中使用,但我不能让它们在页脚中使用。

$FN = $data[0]['data']['FN2'];
$LN = $data[0]['data']['LN2'];
$Name = $FN.' '.$LN;

$this->Cell(40,8,$Name,0,0,'R');
//I also tried this but it didn't work either.I got this error-  Using $this when not in object context.
var $Name;
$FN = $data[0]['data']['FN2'];
$LN = $data[0]['data']['LN2'];
$this->Name = $FN.' '.$LN;

$this->Cell(40,8,$this->Name,0,0,'R');
4

2 回答 2

0

如果

$data

恰好是空的,那么

$FN

$LN

将是未定义的,导致

$Name

未定义(或''),因此您不能保证它已设置。

使用 isset 确保它已设置,我还将检查它是否与空字符串匹配。

于 2013-05-02T21:31:32.727 回答
0

将变量称为全局变量就可以了。

$this->Cell(60,4,'X'.$GLOBALS["Name"],'B',0,'L');
于 2013-05-02T21:58:46.310 回答