Solved

pasing variable to instantiated fpdf class

Posted on 2004-09-23
4
695 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
Comment Utility
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
Comment Utility
or if it is inside the object
$mypdf->Header($this->passedv);
0
 

Author Comment

by:webusername
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now