使用 fpdf 库打印数据时数据未传入 codeigniter

While printing data using fpdf library Data is not passing in codeigniter

我有表格,我正在显示 data.When 我点击打印按钮 我将以 pdf 格式保存数据以便打印 我正在使用 FPDF Library.The 问题是什么时候我从控制器发送数据以仅查看 headers 显示如下但数据未显示。 我已经编写了我的视图文件 below.I 自从 yesterday.I 以来就卡住了已在控制器中获取数据但未传递给 view.I 无法理解为什么会发生这种情况。我做错的方式或请任何帮助提前 Appreciated.Thanks。

我的控制器代码

 public function printpage(){
                 $this->load->library('Myfpdf');
                 $data['result']=$this->Vendor_Model->displaydata();
                 if(!empty(array_filter($data))){
                  $this->load->view('Savedata',$data);
                 }else{
                 redirect('Vendorcontroller/showeditview');
                 }

                 } 

我从数据库中获取数据的模态代码

  public function displaydata(){
      $query=$this->db->query('SELECT `vndr_id`, s.state as state,`vndr_name`, `vndr_address`, `vndr_pincode`, `vndr_telephone`, `vndr_mobile`, `vndr_mailid`, `vndr_country`, `vndr_gsttin`, `vndr_cstno`, `vndr_totaldebit`, `vndr_totalcredit`, `vndr_bankname`, `vndr_acno`, `vndr_ifsccode` FROM `vendors` vndr INNER JOIN states s ON vndr_state=s.state_id order by vndr_id');
      if($query->num_rows()>0){
        return $query->result_array();
      }
    } 

我将数据打印为 pdf 格式的查看代码

class printview extends FPDF
{
  function Header()
  {
    $this->SetFont('Arial','B',15);
    $this->Cell(276,5,"VendorDetails",0,0,'C');
    $this->ln(15);
    $this->SetFont('Arial','B',10);
    $this->Cell(55,10,"Name",1,0,'C');
    $this->Cell(90,10,"Address",1,0,'C');
    $this->Cell(50,10,"Telephone",1,0,'C');
    $this->Cell(70,10,"Email",1,0,'C');
    $this->ln();
  }
function Footer(){
$this->SetY(-15);
$this->SetFont('Arial','I',8);
 $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}


function viewdata(){
if(isset($result)){
  foreach($result as $values){
  $this->SetFont('Arial','',10);
  $this->Cell(55,10,$values['vndr_name'],1,0,'L');
  $this->Cell(90,10,$values['vndr_address'].','.$values['state'].'-'.$values['vndr_pincode'],1,0,'L');
  $this->Cell(50,10,$values['vndr_telephone'].','.$values['vndr_mobile'],1,0,'L');
  $this->Cell(70,10,$values['vndr_mailid'],1,0,'L');
  $this->ln();
}
}
}

}

$this->pdf = new Printview();
$this->pdf->SetMargins(15, 10, 20);
$this->pdf->AliasNbPages();
$this->pdf->AddPage('L','A4',0);
$this->pdf->viewdata();
$this->pdf->Output();

这是 Fdf 库 class

require('fpdf/fpdf.php');

class Myfpdf extends fpdf
{
function __construct(){
  parent::__construct();
  $ci=& get_instance();
}

}

尝试将 $result 数据作为参数传递:

$this->pdf->viewdata($result);

还有方法:

function viewdata($result){
...
}

我已经改成现在可以正常使用了。

   This is controller
   -------------------------
        public function printpage(){
                 $this->load->library('Myfpdf');
                 $data['result']=$this->Vendor_Model->displaydata();
                 if(!empty(array_filter($data))){
                  $this->load->view('Savedata',$data);
                 }else{
                 redirect('Vendorcontroller/showeditview');
                 }

                 } 

这是视图文件

function viewdata($result){
if(isset($result)){
  foreach($result as $values){
  $this->SetFont('Arial','',10);
  $this->Cell(55,10,$values['vndr_name'],1,0,'L');
  $this->Cell(90,10,$values['vndr_address'].','.$values['state'].'-'.$values['vndr_pincode'],1,0,'L');
  $this->Cell(50,10,$values['vndr_telephone'].','.$values['vndr_mobile'],1,0,'L');
  $this->Cell(70,10,$values['vndr_mailid'],1,0,'L');
  $this->ln();
}
}
}

}

$this->pdf = new Printview();
$this->pdf->SetMargins(15, 10, 20);
$this->pdf->AliasNbPages();
$this->pdf->AddPage('L','A4',0);
$this->pdf->viewdata($result);
$this->pdf->Output();