简体   繁体   中英

How to load multiple views to mpdf

Just a quick question. Anyone know if its possible to load multiple views from codeigniter to mpdf controller and convert it to pdf? my controller : `

<?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();

}

}?>

i want to add footer and header from other view.

Just prefetch the header and footer templates into variables and pass their parsed strings to the main view ,like this:

$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); 

Notice the third parameter to true so that you get the view in a string instead of sending it to output (most commonly the client's browser).

Then in your main template, place the $header and $footer variables wherever you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM