[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 960
  • Last Modified:

pasing variable to instantiated fpdf class

i am trying to generate reports using fpdf. i instantiates a class mypdf that extends fpdf. I am supposed to pass a variable to my header so that a heading, created at the top of the page , will contain the value of that variable. i tried this
function Header ($variablepassed)
{...

$this->Cell(0,1,$variablepassed,0,0,'C');
....
}

i added the line
var $passedv='dumy';
$mypdf->Header(passedv);

when i run the program , it gives an error such as does not reconizes function
ps: in my original fpdf file , there is only function Header ,which is empty .
thanks for the help
0
webusername
Asked:
webusername
  • 2
1 Solution
 
hernst42Commented:
The problem is that you don't pass a variable to that function the $ is missing

Try $mypdf->Header($passedv);

0
 
hernst42Commented:
or if it is inside the object
$mypdf->Header($this->passedv);
0
 
webusernameAuthor Commented:
i want to mention that i tried this below and got the same error
$mypdf->Header('dummy');
0
 
RoonaanCommented:
As far as I know, php4.x does not support extending a class and then adding a argument to its functions. You should do something like this.

class myPDF extends FPDF
{
  var $header_text;
  function myHeader($text)
  {
     $this->header_text = $text;
     $this->Header();
  }
  function Header()
  {
    $this->Cell(0,1,$this->header_text,0,0,'C');
  }
}

But then again, you are not supposed to do the call to Header() yourself, because it is called automatically when adding a new page. Therefor better would be:

class myPDF extends FPDF
{
  var $header_text;
  function setHeader($text)
  {
     $this->header_text = $text;
  }
  function Header()
  {
    $this->Cell(0,1,$this->header_text,0,0,'C');
  }
}

Regards

-r-
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now