我在这里有点困惑,
我正在使用TCPDF从Codeigniter打印pdf。 TCPDF目录放在应用程序/库
中我想从模型加载一行到我修改过的TCPDF标题,因为 标题将查看一些数据,如模型中的序列号。
模型是这样的:
class model_request extends CI_Model{
public function __construct(){
parent::__construct();
}
public function selectOneRequest($id_request){
$query = $this->db->get_where('tbl_requestfix', array('id_request'=>$id_request));
return $query->result_array();
}
}
这是扩展tcpdf类的标题dan footer的mypdf类
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once dirname(__FILE__) . '/tcpdf/tcpdf.php';
class TC_Pdf extends TCPDF{
//Page header
public function Header() {
// Set font
$this->SetFont('helvetica', '', 10);
// Serial number
$this->Cell(0, 15, 'I am missing here', 0, true, 'R', 0, '', 0, false, 'M', 'M');
$this->SetFont('helvetica', 'B', 16);
$this->Cell(0, 15, 'P.T. Tresnamuda Sejati', 0, true, 'C', 0, '', 0, false, 'M', 'M');
$this->SetFont('helvetica', '', 11);
$this->Cell(0, 15, 'FORM PERMINTAAN / PERBAIKAN ', 0, true, 'C', 0, '', 0, false, 'M', 'M');
$this->SetFont('helvetica', 'B', 16);
$this->Cell(0, 15, 'HARDWARE - SOFTWARE - NETWORK', 0, true, 'C', 0, '', 0, false, 'M', 'M');
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-10);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
//$this->Cell(0, 0, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
这是我的控制器填写pdf的主体:
public function generate_pdf($idRequest){
$data=$this->model_request->selectOneRequest($idRequest);
foreach ($data as $d) {
$this->load->library("TC_PDF");
$pdf = new TC_Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Dzil');
$pdf->SetTitle('Form Perbaikan / Permintaan');
$pdf->SetSubject('TMS/DEPT/IT/06');
$pdf->SetKeywords('TCPDF, PDF, form, perbaikan, Permintaan');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 12);
// add a page
$pdf->AddPage();
$pdf->Ln(8);
$pdf->Cell(30, 8, 'Nama', 1, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 4, 8, ': ', 1, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 8, $d['nama_user'], 1, 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 8, 'Departement', 1, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 4, 8, ': ', 1, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 8, $d['departement'], 1, 1, 'L', 0, '', 0, false, 'T', 'C'); //w,h,isi, border
$pdf->Cell(30, 8, 'NIK', 1, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 4, 8, ': ', 1, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 8, $d['id_user'], 1, 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 8, 'Tanggal', 1, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 4, 8, ': ', 1, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 8, $d['waktu_mulai'], 1, 1, 'L', 0, '', 0, false, 'T', 'C');
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_057.pdf', 'I');
//echo $d["kode_kantor"];
}
}
我应该怎么做,因为在mypdf类中扩展了tcpdf类,我无法加载该模型... 任何帮助它如此苛刻......
答案 0 :(得分:0)
您是否在控制器中加载了该模型?
在调用模型之前插入它。
public function generate_pdf($idRequest){
$this->load->model('model_request'); // <-- insert this
$data=$this->model_request->selectOneRequest($idRequest);
...
}