Solved

pasing variable to instantiated fpdf class

Posted on 2004-09-23
4
794 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
[X]
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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

726 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