access varible value from a function in a class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perhapscwk
    New Member
    • Sep 2007
    • 123

    access varible value from a function in a class

    Inside the function Header, I want to display the logo and the variable $this->test , but finally my PDF file can show the logo only.

    please help. Thanks.

    Code:
    require_once('../config/lang/eng.php');
    require_once('../tcpdf.php');
    [B]$test="test 1";
    [/B]
    // Extend the TCPDF class to create custom Header and Footer
    class MYPDF extends TCPDF {
    
    	//Page header
    	public function Header() {
    		// Logo
    		$image_file = K_PATH_IMAGES.'logo_example.jpg';
    		$this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
    		// Set font
    		$this->SetFont('helvetica', 'B', 20);
    		// Title
    		$this->Cell(0, 15, '[B]$this->test[/B]', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    	}
    }
    
    // create new PDF document
    $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Your code makes no sense.
    Neither does your question to be honest.

    Comment

    • perhapscwk
      New Member
      • Sep 2007
      • 123

      #3
      I have amended my code and my questions, please help.

      thanks.

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        $test is not a class member so you cannot access it with $this->test.
        It needs passing to the function Header($test) when you call it

        Comment

        Working...