如何将多个视图加载到 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 变量放在您需要的任何位置。
只是一个简短的问题。任何人都知道是否可以将多个视图从 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 变量放在您需要的任何位置。