【问题标题】:load row data on modify header tcpdf codeigniter在修改标题 tcpdf codeigniter 上加载行数据
【发布时间】:2015-01-14 06:41:52
【问题描述】:

我有点困惑,

我正在使用 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 类的页眉和页脚的 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"];
    }
  }

我该怎么办,因为在扩展 tcpdf 类的 mypdf 类中,我无法加载该模型... 任何帮助它如此appriciated...

【问题讨论】:

    标签: codeigniter model tcpdf


    【解决方案1】:

    您是否在控制器中加载了该模型?

    在调用模型之前插入它。

    public function generate_pdf($idRequest){
        $this->load->model('model_request'); // <-- insert this
        $data=$this->model_request->selectOneRequest($idRequest);
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      • 1970-01-01
      相关资源
      最近更新 更多