Solved

pasing variable to instantiated fpdf class

Posted on 2004-09-23
4
731 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use embargo Date/time in php 29 39
Selecting SUM data from mysql table with PHP 4 19
error log using ftp 7 41
PHP AJAX JSON 2 61
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.  …
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 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…

777 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