问题描述:

I'm trying to get the first and last name from my array into the footer but I'm getting undefined variable error. This would work in the body of the PDF but I cant get them to work in the footer.

$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');

网友答案:

If

$data

happens to be empty, then

$FN

and

$LN

Will be undefined, causing

$Name

to be undefined (or ' ') so you can't guarantee that it is set.

Use isset to make sure that it's set, I would also check if it matches the empty string or not.

网友答案:

Calling the variable as a global did the trick.

$this->Cell(60,4,'X'.$GLOBALS["Name"],'B',0,'L');
相关阅读:
Top