致命错误:调用未定义的方法FPDF

时间:2013-07-03 01:10:15

标签: fatal-error fpdf

我收到此错误消息。请帮我解决。

致命错误:在第38行的C:\ xampp \ htdocs \ sikembul \ application \ views \ viw_slip_gaji.php中调用未定义的方法FPDF :: check()

这是我的代码

<?php
$GLOBALS['a']=2;
$GLOBALS['alpha']=3;
$GLOBALS['beta']=5;


function check($num)
{
    if ($num=="1")
    {
        global $a;
        global $alpha;
        global $beta;

        $total = $a*$alpha*$beta;
        $this->fpdf->Cell(50,5,'final',1,0,'L');
        $this->fpdf->Cell(8,5,'xx.',1,0,'L');
        $this->fpdf->Cell(20,5,$total,1,1,'R');
    }
    else 
    {
        global $a;
        global $alpha;
        global $beta;

        $total = $a-$alpha-$beta;
        $this->fpdf->Cell(50,5,'final',1,0,'L');
        $this->fpdf->Cell(8,5,'xx.',1,0,'L');
        $this->fpdf->Cell(20,5,$total,1,1,'R');
    }
}

$this->fpdf->FPDF('P','mm','A5');
$this->fpdf->SetMargins(10,10,10);
$this->fpdf->AddPage();
$this->fpdf->setFont('Times','B',9);
$this->fpdf->Cell(130,5,'Here Some Text to Display',0,1,'C');
$this->fpdf->check(1);

$this->fpdf->Output('generate.pdf','I');
?>

仅供参考,当我禁用该功能时,一切正常。 感谢所有的帮助和评论。

1 个答案:

答案 0 :(得分:0)

你可以试试这个。将实例传递给函数可能会起作用。这只是一个快速的示例,可能无法按预期工作,但它说明了我在评论中建议的内容。

<?php
$GLOBALS['a']=2;
$GLOBALS['alpha']=3;
$GLOBALS['beta']=5;


function check($num, &$fpdf)
{
    global $a;
    global $alpha;
    global $beta;

    if ($num=="1")
    {
        $total = $a*$alpha*$beta;
        $fpdf->Cell(50,5,'final',1,0,'L');
        $fpdf->Cell(8,5,'xx.',1,0,'L');
        $fpdf->Cell(20,5,$total,1,1,'R');
    }
    else 
    {
        $total = $a-$alpha-$beta;
        $fpdf->Cell(50,5,'final',1,0,'L');
        $fpdf->Cell(8,5,'xx.',1,0,'L');
        $fpdf->Cell(20,5,$total,1,1,'R');
    }
}

$this->fpdf->FPDF('P','mm','A5');
$this->fpdf->SetMargins(10,10,10);
$this->fpdf->AddPage();
$this->fpdf->setFont('Times','B',9);
$this->fpdf->Cell(130,5,'Here Some Text to Display',0,1,'C');
check(1, $this->fpdf);

$this->fpdf->Output('generate.pdf','I');
?>