I Have form in that i am displaying data.When I click on the print button I am going to save the data in pdf format for printing for that I am using FPDF Library.The problem is when i send the data from the controller to view only headers displaying like below But Data is not displaying. I have written my view file like below.I have got stuck since yesterday.I Have getting the data in controller but not passing to the view.I can't understand why it is happening .The Way i am doing wrong or what please any help Would be Appreciated.Thanks in Advance.
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();
}
}
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();
require('fpdf/fpdf.php');
class Myfpdf extends fpdf
{
function __construct(){
parent::__construct();
$ci=& get_instance();
}
}
Try to pass the $result
data as a parameter :
$this->pdf->viewdata($result);
And also on the method :
function viewdata($result){
...
}