簡體   English   中英

如何將多個視圖加載到mpdf

[英]How to load multiple views to mpdf

只是一個簡單的問題。 有人知道是否可以從codeigniter加載多個視圖到mpdf控制器並將其轉換為pdf? 我的控制器:`

<?php

class C_Pdf extends CI_Controller {

private $params = array();

  function __construct() {
    parent::__construct();
    $this->params['set_tag'] = array();
    $this->params['set_css'] = array();
    $this->params['set_js'] = array();
    $this->params['title_auto'] = true;
    $this->params['title'] = '';
  }
public function index(){

//this data will be passed on to the view
$data['the_content']='mPDF and CodeIgniter are cool!';
$data['other']="siema heniu cos przeszlo";
//load the view, pass the variable and do not show it but "save" the output into $html variable
 $this->load->view('common/default_header',$this->params);
$html=$this->load->view('reservation/complete', $data,true);  
$this->load->view('common/default_footer');
//this the the PDF filename that user will get to download

//load mPDF library
$this->load->library('m_pdf');
//actually, you can pass mPDF parameter on this load() function
$pdf = $this->m_pdf->load();
//generate the PDF!
$pdf->WriteHTML($html);
//offer it to user via browser download! (The PDF won't be saved on your server HDD)
$pdf->Output();

}

}?>

我想從其他視圖添加頁腳和標題。

只需將頁眉和頁腳模板預取到變量中,然后將解析后的字符串傳遞給主視圖,如下所示:

$data['header'] = $this->load->view('common/default_header',$this->params, true);
$data['footer'] = $this->load->view('common/default_footer', true);
$html = $this->load->view('reservation/complete', $data, true); 

請注意第三個參數true,以便您以字符串形式獲取視圖,而不是將其發送到輸出(最常見的是客戶端的瀏覽器)。

然后在主模板中,將$ header$ footer變量放在任何需要的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM