您将在下面看到的是用于在月末生成报告的代码,该按钮用于单击以生成报告,并根据月份和年份进行排序。
此文件有效,但我在标题部分有问题,这是代码:
//Title
$this->SetFont('Arial','',18);
$this->Image('media/logo.png');
$this->Ln(10);
$this->Cell(0,6,'Generated Reports',0,1,'C');
$this->Cell(0,7,'As of Month of ',0,2,'C');
if($date=="01")
{
$pdf->Cell(0,8,'January',0,3,'C');
}
else if($date=="02")
{
$pdf->Cell(0,8,'February',0,3,'C');
}
else if($date=="03")
{
$pdf->Cell(0,8,'March',0,3,'C');
}
else if($date=="04")
{
$pdf->Cell(0,8,'April',0,3,'C');
}
else if($date=="05")
{
$pdf->Cell(0,8,'May',0,3,'C');
}
else if($date=="06")
{
$this->Cell(0,8,'June',0,3,'C');
}
else if($date=="07")
{
$this->Cell(0,8,'July',0,3,'C');
}
else if($date=="08")
{
$this->Cell(0,8,'August',0,3,'C');
}
else if($date=="09")
{
$this->Cell(0,8,'September',0,3,'C');
}
else if($date=="10")
{
$this->Cell(0,8,'October',0,3,'C');
}
else if($date=="11")
{
$this->Cell(0,8,'November',0,3,'C');
}
else if($date=="12")
{
$this->Cell(0,8,'December',0,3,'C');
}
$this->Ln(10);
//Ensure table header is output
parent::Header();
日期是数字,因此1月是2月1日= 02,依此类推,直到12月12日。
正如您在上面所看到的,我尝试使用if甚至将$this
更改为$pdf
,但仍然无济于事。
它将生成一个PDF文件但没有月份,它只会生成"截至"以及它下面的详细信息,但不是它生成的月份。
答案 0 :(得分:0)
我建议您使用数组来管理它。
不要混淆和错过使用$ this(Class member)& $ pdf(Class Object)
//Title
$this->SetFont('Arial','',18);
$this->Image('media/logo.png');
$this->Ln(10);
$this->Cell(0,6,'Generated Reports',0,1,'C');
$monthArray = array("January","February","March","April","May","June","July","August","September","October","November","December");
$index = intval($date)-1;
$this->Cell(0,7,'As of Month of '.$monthArray[$index],0,2,'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();