tags:

views:

116

answers:

3

Hi, I am extending FPDF and want to include some external variables but it's not working. What am I doing wrong?

<?php

class PDF extends FPDF {

    public var $DocNum; 
    public var $cliente;
    public var $noCliente; 
    public var $noTienda;
    public var $noPedido;

    function Header() {
        $this->Image('fpdf/cabMCR.jpg',5,10,100,0,'JPG','');

        $this->SetFont('Arial','B','16');
        $this->SetXY(125,15);
        $this->Write(5,'FACTURA');

        // doing some more stuff here
    }

    function Footer() {
        $this->SetTextColor(150,150,150);
        $this->SetXY(10,285);
        $this->SetFont('Helvetica','I',7);
        $this->Write (5, 'MCR Electronic S.L. Inscrita en el Registro Mercantil de Madrid en Tomo 15819, folio 163, Seccion 8ª, hoja M-267058, CIF: B82766452');
        $this->SetTextColor(0,0,0);
    }
}

$pdf=new PDF();

$pdf->Open();
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default'); 
$pdf->SetAuthor('Company S.L');
$pdf->SetTitle('Factura MCR');

$pdf->$DocNum = $DocNum;
$pdf->$cliente = $cliente;
$pdf->$noCliente = $noCliente; 
$pdf->$noTienda = $noTienda;
$pdf->$noPedido = $noPedido;

?>
+2  A: 

You don't want to reference class members with a $ unless you're doing something kind of strange with variable variables.

Instead of this:

$pdf->DocNum = $DocNum;
$pdf->$cliente = $cliente;
$pdf->$noCliente = $noCliente; 
$pdf->$noTienda = $noTienda;
$pdf->$noPedido = $noPedido;

It should be more like this:

$pdf->DocNum    = 'somevalue';
$pdf->cliente   = 'somevalue';
$pdf->noCliente = 'somevalue';
$pdf->noTienda  = 'somevalue';
$pdf->noPedido  = 'somevalue';
AvatarKava
If there is more than 1 `$` in a variable, it tries to look up that variable to create a variable variable.
Chacha102
I did it like you said and I don't get an error anymore but I also don't get the var passed through...
mistero
You'll need to change the instances where I put 'somevalue' on the right side into whatever values/variables you want to set those class members to.
AvatarKava
A: 

You are doing it wrong! Should be like this:

$pdf->DocNum = $DocNum;
$pdf->cliente = $cliente;
$pdf->noCliente = $noCliente; 
$pdf->noTienda = $noTienda;
$pdf->noPedido = $noPedido;

Suerte!

Adrián
A: 

Im cheking it and I receive this:

Parse error: syntax error, unexpected T_VAR, expecting T_VARIABLE in /var/www/vhosts/mcr.com.es/subdomains/beta/httpdocs/includes/modulos/tools.php on line 473