0

我收到此错误消息。请帮我解决这个问题。

致命错误:在第 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');
?>

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

4

1 回答 1

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');
?>
于 2013-07-03T01:42:05.770 回答