Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

pasing variable to instantiated fpdf class

Posted on 2004-09-23
4
742 Views
Last Modified: 2012-05-05
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
Comment
Question by:webusername
  • 2
4 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12138508
The problem is that you don't pass a variable to that function the $ is missing

Try $mypdf->Header($passedv);

0
 
LVL 48

Expert Comment

by:hernst42
ID: 12138519
or if it is inside the object
$mypdf->Header($this->passedv);
0
 

Author Comment

by:webusername
ID: 12138537
i want to mention that i tried this below and got the same error
$mypdf->Header('dummy');
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 12140383
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question